【问题标题】:setUbiquitous: error code = 513setUbiquitous:错误代码 = 513
【发布时间】:2013-09-20 14:48:13
【问题描述】:

我正在尝试使用 NSFileManagersetUbiquitous API 将文件从捆绑包保存到 iCloud,但它返回 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);
});

}

提前致谢

【问题讨论】:

    标签: ios ios5 icloud nsfilemanager


    【解决方案1】:

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

    NSURL * newDocumentURL = [[fm URLForUbiquityContainerIdentifier:nil]URLByAppendingPathComponent:filename] ;
    
    BOOL saved = [fm setUbiquitous:YES itemAtURL:[NSURL fileURLWithPath:filePath] destinationURL:newDocumentURL error:&error];
    

    【讨论】:

      猜你喜欢
      • 2019-12-28
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 1970-01-01
      • 2012-12-15
      • 2011-03-27
      • 2019-09-22
      • 1970-01-01
      相关资源
      最近更新 更多