1

我正在尝试使用setUbiquitousAPI将文件从捆绑包保存到 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);
});

}

提前致谢

4

1 回答 1

0

编辑您的代码,如下所示:

NSURL * newDocumentURL = [[fm URLForUbiquityContainerIdentifier:nil]URLByAppendingPathComponent:filename] ;

BOOL saved = [fm setUbiquitous:YES itemAtURL:[NSURL fileURLWithPath:filePath] destinationURL:newDocumentURL error:&error];
于 2014-04-12T08:57:46.343 回答