我正在尝试直接在 iCloud 文件夹中创建一个文件,当我尝试对 iCloud 文件夹进行 fopen 时,我面临的问题总是返回 0x0
有没有办法做到这一点?我知道我应该使用 UIDocument 或各种协议,但我只想要一种简单明了的方式来访问该文件夹,就像访问普通文件夹一样。
FILE* file;
NSURL tmp = [ubiq URLByAppendingPathComponent:@"Documents"];
char* folder = (char*) [[tmp absoluteString] fileSystemRepresentation];
sprintf(folder, "%s/file1.txt", folder);
file = fopen(folder, "rw+");
fprinf(file, "%s", "this is just an example");
fclose(file);
我还手动尝试了以下文件夹:
file://localhost/private/var/mobile/Library/Mobile%20Documents/XXXXXX~com~name~app/Documents/file1.txt
//localhost/private/var/mobile/Library/Mobile%20Documents/XXXXXX~com~name~app/Documents/file1.txt
/private/var/mobile/Library/Mobile%20Documents/XXXXXX~com~name~app/Documents/file1.txt
/var/mobile/Library/Mobile%20Documents/XXXXXX~com~name~app/Documents/file1.txt
/var/mobile/Library/Mobile%20Documents/XXXXXX.com.name.app/Documents/file1.txt
/var/mobile/Library/Mobile Documents/XXXXXX~com~name~app/Documents/file1.txt
/var/mobile/Library/Mobile Documents/XXXXXX.com.name.app/Documents/file1.txt
作为 fopen() 函数调用的结果,它们都返回了 0x0;
先感谢您。
PD:我已经使用 NSFileManager 类成功创建了一个文件。