ios - Can't Create a new file using NSData writeFile, NSFileManager and NSURL never returns the filePath -


this question has answer here:

am working on ios app , having huge bad time on issue, here thing:

1.- creating file based on nsdata 2.- trying retrieve nsurl of new file created

the issue nsurl doesn't seems find file, have attempt create 2 different methods

nsdata * filedata = /*gets data of file web*/  if([filedata writetofile:databasepath atomically:yes]) {      nslog(@"path resource :%@", [[[nsbundle mainbundle] pathforresource:@"mytmp"  oftype:@"epub"] description]);     //this causes exception cause string nil means file created     return [nsurl fileurlwithpath:[[nsbundle mainbundle] pathforresource:@"mytmp" oftype:@"epub"]];  } 

if try this:

nsstring* path=@"mytmp.epub"; [filedata writetofile:path options:nsdatawritingatomic error:&error]; nslog(@"write returned error: %@", [error localizeddescription]); 

it never creates new file, help, suggestions, comments appreciated best regards,

jorge.

you not allowed write application bundle, obvious security reasons. you'll need write documents or other application bundle folder. use nsfilemanager's urlsfordirectory:indomains: method documented here:

http://developer.apple.com/library/ios/documentation/filemanagement/conceptual/filesystemprogrammingguide/accessingfilesanddirectories/accessingfilesanddirectories.html#//apple_ref/doc/uid/tp40010672-ch3-sw3

see http://developer.apple.com/library/ios/documentation/filemanagement/conceptual/filesystemprogrammingguide/filesystemoverview/filesystemoverview.html#//apple_ref/doc/uid/tp40010672-ch2-sw2 more general information relating reading & writing files on ios.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -