在ios中从iCloud获取文件时出错

时间:2015-08-31 06:41:33

标签: objective-c icloud

您好我的应用程序我必须从iCloud获取文件..我启用iCloud在模拟器中工作正常..但是当我在iPhone中测试时,我可以看到iCloud文件,当我选择默认的委托调用但我可以&# 39;从网址获取数据..

- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
{
    NSData *pdfData = [[NSData alloc] initWithContentsOfURL:url];
} 

我始终以pdfData为零。我记录了错误

Error Domain=NSCocoaErrorDomain Code=257 "The operation couldn’t be completed. (Cocoa error 257.)" UserInfo=0x17029810 {NSFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/download (2).jpeg, NSUnderlyingError=0x15ea9680 "The operation couldn’t be completed. Operation not permitted"}

我无法弄清楚..你能不能帮我解决这个问题..

1 个答案:

答案 0 :(得分:10)

最后我找到了自己的答案..请参阅此链接Here

- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url
{
    [url startAccessingSecurityScopedResource];
    __block NSData *pdfData = nil;

    NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] init];
    __block NSError *error;
    [coordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {
        pdfData = [NSData dataWithContentsOfURL:newURL];
    }];
    [url stopAccessingSecurityScopedResource];
}