简体   繁体   中英

iPhone write to file (alternative directory)

New to iPhone 3.2, Apple introduced File-Sharing support. Details can be found at https://developer.apple.com/iphone/library/releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS3_2.html#//apple_ref/doc/uid/TP40009337-SW1 .

Now, most examples floating around in the web demonstrates writing to the documents directory. What if I want to write files from my app but I don't want the user to be able to see it via iTunes? I'm looking at the Files and Networking section of the iPhone OS Programming Guide and I'm unsure what would be a good alternative to the documents directory for writing files to hide from the user and not be rejected by Apple's review team.

If the data doesn't need to persist each launch you could use the Temps folder. Aptly named, it is a volatile (across launch) folder.

You can use the library directory instead of the document directory:

// get the library directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *libraryDirectory = [paths objectAtIndex:0];

// make a file name to write the data to using the library directory:
NSString *fileName = [NSString stringWithFormat:@"%@/myfile", libraryDirectory];

// Save data
[myData writeToFile:fileName atomically:NO];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM