我正在尝试使用setUbiquitous
API将文件从捆绑包保存到 iCloud NSFileManager
,但它会返回error code= 513
,
NSUnderlyingError=0x1e099830 "The operation couldn’t be completed. Operation not permitted".
请任何人帮我解决这个问题。
- (IBAction)addFileToiCloud:(id)sender {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *localPath = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"rtf"];
NSURL *localURL = [NSURL URLWithString:localPath];
NSLog(@"Local file path = %@",localURL);
// Create the new URL object on a background queue.
NSFileManager *fm = [NSFileManager defaultManager];
NSString *filename = @"test.rtf";
NSURL * newDocumentURL = [[[fm
URLForUbiquityContainerIdentifier:nil]URLByAppendingPathComponent:@"Documents"
isDirectory:YES] URLByAppendingPathComponent:filename];
NSLog(@"***** iCloud = %@",newDocumentURL);
NSError *error;
BOOL saved = [fm setUbiquitous:YES itemAtURL:localURL destinationURL:newDocumentURL error:&error];
NSLog(@"Error = %@",error);
NSLog(@"New Document URL = %d",saved);
});
}
提前致谢