首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可可错误262,无法将文件上载到iCloud

可可错误262,无法将文件上载到iCloud
EN

Stack Overflow用户
提问于 2013-08-21 11:01:45
回答 2查看 2.6K关注 0票数 4

我试图使用以下几行代码将一个大文件上载到iCloud:

代码语言:javascript
复制
-(void)uploadFileWithFilePath:(NSString *)Path toFileURLInCloud:(NSURL *)destURL{
    NSURL * filePath = [NSURL URLWithString:Path];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void)
    {
        NSFileCoordinator* fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
        [fileCoordinator coordinateReadingItemAtURL:filePath
                            options:NSFileCoordinatorReadingWithoutChanges
                              error:nil
                         byAccessor:^(NSURL *newURL)
        {
            NSFileManager * fileManager = [[NSFileManager alloc] init];
            NSError * error;
            BOOL success = [fileManager copyItemAtURL:filePath toURL:destURL error:&error];
            if (success) {
                NSLog(@"Copied %@ to %@", filePath, destURL);
            }
            else {
                NSLog(@"Failed to copy %@ to %@: %@", filePath, destURL, error.localizedDescription);
            }
        }];
    });
}

我知道这个错误

代码语言:javascript
复制
The operation couldn’t be completed. (Cocoa error 262.)

这里有什么问题吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-08-21 11:12:45

我刚刚替换了这行代码:

代码语言:javascript
复制
BOOL success = [fileManager copyItemAtURL:filePath toURL:destURL error:&error];

关于以下几个方面:

代码语言:javascript
复制
BOOL success = [fileManager setUbiquitous:YES itemAtURL:filePath destinationURL:destURL error:&error];

问题解决了。:)

票数 3
EN

Stack Overflow用户

发布于 2013-08-21 11:07:04

好吧,web似乎认为这通常是通过使用字符串路径初始化url引起的。我建议改变这一点:

代码语言:javascript
复制
NSURL * filePath = [NSURL URLWithString:Path];

对此:

代码语言:javascript
复制
NSURL * filePath = [NSURL fileURLWithPath:Path];
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18355668

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档