writetofile - Why can't I save files to my iOS apps /Documents directory? -


i writing app can access ios root system, user should able save files document directory. using code save file document directory.

for text:

nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory,                                                                  nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; [self.filepath writetofile:[nsstring stringwithformat:@"%@/%@", documentsdirectory, [self.filepath lastpathcomponent]]                                            atomically:yes                                              encoding:nsutf8stringencoding error:nil]; 

for other files:

nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory,                                                                  nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; [self.filepath writetofile:[nsstring stringwithformat:@"%@/%@", documentsdirectory,[self.filepath lastpathcomponent]]                                            atomically:yes]; 

my problem can save .txt files, not other files, if save example .plist files save text methods, contact replaced directory path of file. when save picture, or other file isn't readable. there method save files without destroying them?

here have example of saving image:

assuming content of image nsdata object:

nsdata *pngdata = uiimagepngrepresentation(image); 

then write file:

nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);   nsstring *documentspath = [paths objectatindex:0]; //get docs directory  nsstring *filepath = [documentspath stringbyappendingpathcomponent:@"image.png"]; //add file name [pngdata writetofile:filepath atomically:yes]; //write file 

have question , this more detailed explanation


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -