iPhone写入文件(备用目录)

发布于 2024-08-31 08:14:33 字数 543 浏览 3 评论 0 原文

Apple 引入了文件共享支持,这是 iPhone 3.2 的新功能。详细信息可以在 https://developer.apple.com/iphone/library/releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS3_2.html#//apple_ref/doc/uid/TP40009337-SW1

现在,网络上流传的大多数示例都演示了如何写入文档目录。如果我想从应用程序写入文件,但不希望用户能够通过 iTunes 查看该文件,该怎么办?我正在查看 iPhone OS 编程指南的文件和网络部分,我不确定什么是文档目录的良好替代方案,用于编写文件以隐藏用户且不会被 Apple 审核团队拒绝。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各自安好 2024-09-07 08:14:33

如果数据不需要每次启动时都保留,您可以使用 Temps 文件夹。顾名思义,它是一个易失性(跨启动)文件夹。

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.

甜尕妞 2024-09-07 08:14:33

您可以使用库目录代替文档目录:

// 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];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文