调用setUbiquitous时出错代码512:

时间:2013-04-26 17:31:00

标签: objective-c objective-c-blocks icloud

我知道之前已经问过这个问题,但到目前为止,我发现的帖子都没有解决我的问题。

这是我的代码

NSURL *ubiquitousPackage = [[ubiq URLByAppendingPathComponent:
                                     @"Documents"] URLByAppendingPathComponent: kCloudStorageFileName];

CloudDocument *doc = [[[CloudDocument alloc] initWithFileURL:ubiquitousPackage] autorelease];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
{
       NSError* error = [[[NSError alloc] init] autorelease];
       if ([[NSFileManager defaultManager] setUbiquitous: true itemAtURL: [doc fileURL] destinationURL: ubiquitousPackage error: &error])
       {
          NSLog(@"Moved Cloud successfully");
       }
       else
       {
          NSLog(@"Error: %@", error);
       }
});

我收到错误,我不知道如何修复它。 希望有人可以帮助我:(

    Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)"
 UserInfo=0x1f82a3b0 
{NSURL=file://localhost/private/var/mobile/Library/Mobile%20Documents/QR39Z776YC~com~something~testApp/Documents/cloudSavedData.doc, NSUnderlyingError=0x1f82a820 "
The operation couldn’t be completed. 

1 个答案:

答案 0 :(得分:-1)

如果文件已经存在,则不应该在其上调用setUbiquitous。使用[NSFileManager isUbiquitousItemAtURL:]确定它是否已经在iCloud中。