ios - NSSearchPathForDirectoriesInDomains NSUserDomainMask -
using urlconnection downloading file url , storing data file in documents directory. when receive response, when didreceiveresponse: method called, create file , move end of file way:
nsstring *filepath = [[nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0] stringbyappendingpathcomponent:self.filename]; nslog(@"filepath %@",filepath); [[nsfilemanager defaultmanager] createfileatpath:filepath contents:nil attributes:nil]; file = [[nsfilehandle filehandleforupdatingatpath:filepath] retain]; [file seektoendoffile]; where file object of nsfilehandle class. later while receiving data, whenever didreceivedata:(nsdata *)data method called, store received data file way:
[file seektoendoffile]; [file writedata:data]; finally close file in connectiondidfinishloading: method way:
[file closefile]; it working when build , run in system. when copied system , tried build error :
terminating app due uncaught exception `'nsfilehandleoperationexception'`, reason: '*** `-[nsconcretefilehandle seektoendoffile]: no such file or directory'` i refered http://www.techotopia.com/index.php/working_with_directories_on_iphone_os , what nssearchpathfordirectoriesindomains? knowing nssearchpathfordirectoriesindomain function still not clear.
will userdomainmask return proper path depending on system , user in project exists. if why getting such error?
they path returned (stored in filepath) path /users//library/application support/iphone simulator/user/application//documents where
name of user logged mac os x system on simulator running , unique id of app
can me, understand why getting such error.
as on requirment no source code , showing exception have these path wrting , reading. , share using ?
documents
nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; library
nsarray *paths = nssearchpathfordirectoriesindomains(nslibrarydirectory, nsuserdomainmask, yes); nsstring *librarydirectory = [paths objectatindex:0]; cache directory
nsarray *paths = nssearchpathfordirectoriesindomains(nscachesdirectory, nsuserdomainmask, yes); nsstring *cachepath = [paths objectatindex:0]; bool isdir = no; nserror *error; if (! [[nsfilemanager defaultmanager] fileexistsatpath:cachepath isdirectory:&isdir] && isdir == no) { [[nsfilemanager defaultmanager] createdirectoryatpath:cachepath withintermediatedirectories:no attributes:nil error:&error]; } for reading , wrting can use path.and more see answer
Comments
Post a Comment