文件操作在设备上不起作用

发布于 2024-12-26 04:10:45 字数 192 浏览 4 评论 0原文

是什么导致在模拟器上运行良好的文件操作在 iOS设备 上无法运行?

当使用[NSBundle mainBundle]时,并且文件是由FileManager找到的,相邻文件操作有不同结果的不同原因可能是什么?

我有时会注意到这一点,只是想知道发生这种情况时应该考虑什么。

What could make a file operation that is working well on the simulator, to not be working on an iOS device?

When using [NSBundle mainBundle], and the file is found by FileManager, what could be the different reasons for adjacent file operations to have different outcome?

I am noticing this sometimes, and just want to get an idea of what to think about when this happens.

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

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

发布评论

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

评论(2

太傻旳人生 2025-01-02 04:10:45

似乎您正在尝试读取应用程序包中的文件。您可以通过代码获取其路径:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"ext"];
//然后你可以使用NSFileManager来读取/复制它

应用程序包中的所有文件都是只读的。您可以从这里获取更多信息:

http://developer.apple.com/library/ios/#documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html#//apple_ref/doc/uid/10000123i-CH104-SW8

Seems like you are trying to read a file in your application bundle. You may get its path by code:

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"ext"];
//Then you can use NSFileManager to read/copy it

All files in application bundle are readonly. You may get more information from here:

http://developer.apple.com/library/ios/#documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html#//apple_ref/doc/uid/10000123i-CH104-SW8

感性 2025-01-02 04:10:45

正如 @Aadhira 在上面的评论中所说,模拟器将其文件存储在 Mac 上的一堆文件夹中,而不是某种模拟的主包/文档目录沙箱中。

为了从主包中获取静态文件,您必须创建一个从 [NSBundle mainBundle] 开始的路径,并向其添加路径组件。

As @Aadhira said in the comment above, the simulator stores its files inside a bunch of folders on your mac, not in some sort of simulated main bundle/docs directory sandbox.

In order to get a static file from your main bundle you must create a path starting from [NSBundle mainBundle] and add path components onto it.

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