4

次のコード行を使用して、大きなファイルを iCloud にアップロードしようとしています。

-(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);
            }
        }];
    });
}

このエラーが発生します

The operation couldn’t be completed. (Cocoa error 262.)

ここで何が問題になる可能性がありますか?

4

2 に答える 2

16

さて、ウェブでは、これは一般的に、URL を文字列パスで初期化することが原因であると考えているようです。これを変更することをお勧めします:

NSURL * filePath = [NSURL URLWithString:Path];

これに:

NSURL * filePath = [NSURL fileURLWithPath:Path];
于 2013-08-21T11:07:04.973 に答える
3

このコード行を置き換えただけです:

BOOL success = [fileManager copyItemAtURL:filePath toURL:destURL error:&error];

次のもので:

BOOL success = [fileManager setUbiquitous:YES itemAtURL:filePath destinationURL:destURL error:&error];

そして問題は解決しました。:))

于 2013-08-21T11:12:45.020 に答える