gpt4 book ai didi

iphone - 为什么我无法将文件写入应用程序的文档目录?

转载 作者:行者123 更新时间:2023-12-03 21:00:13 24 4
gpt4 key购买 nike

我发现了几个描述如何将数据写入用户应用程序文档文件夹的代码片段。但是,当我在 iPhone 模拟器中尝试此操作时,没有创建任何文件。我打电话

[NSFileManager isWritbleAtPath:<my document folder>]

它返回 0(假)。我是否需要使该文件夹显式可写?如果需要,我该怎么做?

最佳答案

iPhone 模拟器应该能够写入整个磁盘。我的应用程序通常将测试文件转储到启动卷的根级别(使用 [NSData's writeToPath:@"/test.jpg"atomically:NO])。

您确定已正确确定文档文件夹的路径吗?您需要扩展路径中的波形符。这是我的应用程序用来将内容放入文档文件夹的代码。我认为不再涉及任何设置!

brushesDir = [[@"~/Documents/BrushPacks/" stringByExpandingTildeInPath] retain];
// create brush packs folder if it does not exist
if (![[NSFileManager defaultManager] fileExistsAtPath: brushesDir])
[[NSFileManager defaultManager] createDirectoryAtPath:brushesDir withIntermediateDirectories:YES attributes:nil error:nil];

关于iphone - 为什么我无法将文件写入应用程序的文档目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1146838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com