iCloud文件夹在iOS中创建和保存
我需要在云中创建文件夹,并将我的.txt文本文件保存到该文件夹中 所以我在AppDelegate中用以下代码创建了一个文件夹 经过测试,它没有显示错误。 所以我假设它在iCloud中创建了Notes文件夹 但是,当我用以下代码将文本文档保存到该文件夹中时,它显示错误且未保存iCloud文件夹在iOS中创建和保存,ios,icloud,nsfilemanager,Ios,Icloud,Nsfilemanager,我需要在云中创建文件夹,并将我的.txt文本文件保存到该文件夹中 所以我在AppDelegate中用以下代码创建了一个文件夹 经过测试,它没有显示错误。 所以我假设它在iCloud中创建了Notes文件夹 但是,当我用以下代码将文本文档保存到该文件夹中时,它显示错误且未保存 NSString *file = [NSString stringWithFormat:@"%@.txt",fileName]; NSURL *ubiq = [[NSFileManager defaultManag
NSString *file = [NSString stringWithFormat:@"%@.txt",fileName];
NSURL *ubiq = [[NSFileManager defaultManager]
URLForUbiquityContainerIdentifier:nil];
NSURL *ubiquitousPackage =
[[[ubiq URLByAppendingPathComponent:@"Documents"] URLByAppendingPathComponent:@"Notes"]
URLByAppendingPathComponent:file];
Note *doc = [[Note alloc] initWithFileURL:ubiquitousPackage];
[doc saveToURL:[doc fileURL] forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
if (!success)
{
NSLog(@"Error");
}
else
{
doc.noteContent = self.txtView.text;
[doc updateChangeCount:UIDocumentChangeDone];
}
}];
错误消息是
Foundation called mkdir("/private/var/mobile/Library/Mobile Documents/35QNLTQU29~com~myapp~iCloudTest/Documents/Notes/(A Document Being Saved By iCloudTest)"), it didn't return 0, and errno was set to 2.
我该怎么解决呢?我可能错了,但在你的第一个片段中,你创建了一个{iCloud}/Notes文件夹,在第二个片段中,你尝试在一个{iCloud}/Documents/Notes文件夹中写入,所以调整其中一个哈哈,不,你是对的D谢谢你的帮助。
Foundation called mkdir("/private/var/mobile/Library/Mobile Documents/35QNLTQU29~com~myapp~iCloudTest/Documents/Notes/(A Document Being Saved By iCloudTest)"), it didn't return 0, and errno was set to 2.