简体   繁体   English

iPhone写入文件(备用目录)

[英]iPhone write to file (alternative directory)

New to iPhone 3.2, Apple introduced File-Sharing support. 苹果机是iPhone 3.2的新功能,引入了文件共享支持。 Details can be found at https://developer.apple.com/iphone/library/releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS3_2.html#//apple_ref/doc/uid/TP40009337-SW1 . 可以在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. 现在,大多数网上示例都展示了如何写入documents目录。 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? 如果我想从我的应用程序写入文件但我不希望用户能够通过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. 我正在查看《 iPhone OS编程指南》中的“文件和网络”部分,不确定将文档隐藏在用户面前并且不会被Apple审核小组拒绝的documents目录的最佳替代方法。

If the data doesn't need to persist each launch you could use the Temps folder. 如果数据不需要每次启动都持久保存,则可以使用Temps文件夹。 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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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