2011-12-17 42 views
1

我遇到了一個錯誤,當我試圖把iCloud的同步關一UIDocument文件UIDocument文件。想知道是否有其他人遇到過這種情況。這裏的情景:錯誤(LibrarianErrorDomain錯誤2)時,轉動的iCloud同步功能,用於setUbiquitous

我在應用程序沙箱本地創建一個UIDocument文件,然後進行下面的調用開始將文件與iCloud的同步:

[[NSFileManager defaultManager] setUbiquitous:YES itemAtURL:localPathURL destinationURL:cloudPathURL error:&error]; 

一切都順順當當。

現在我想停下來的iCloud同步此文件。

我首先要確保該文件已至少被調用同步到iCloud中的以下內容:

- (BOOL) isDataFileSyncedWithCloud 
{ 
    if (![self isICloudSupported] || ![self isUsingICloudForFiles]) 
     return NO; 

    NSURL* file = [self getFileURLToCloudDatafile]; 
    NSNumber* isInCloudNum = nil; 

    if ([file getResourceValue:&isInCloudNum forKey:NSURLIsUbiquitousItemKey error:nil]) 
    { 
     // If the item is in iCloud, see if it is downloaded and uploaded. 
     if ([isInCloudNum boolValue]) 
     { 
      NSNumber* isDownloadedNum = nil; 
      if ([file getResourceValue:&isDownloadedNum forKey:NSURLUbiquitousItemIsDownloadedKey error:nil]) 
      { 
       NSNumber* isUploadedNum = nil; 
       if ([file getResourceValue:&isUploadedNum forKey:NSURLUbiquitousItemIsUploadedKey error:nil]) 
       {      
        return ([isDownloadedNum boolValue] && [isUploadedNum boolValue]); 
       } 
      } 
     } 
    } 

    return NO; 
} 

以上的回報是,表示該文件已被同步(或,所以我想...)

所以,現在我繼續前進,使下面的呼籲停止iCloud的同步此文件:

[[NSFileManager defaultManager] setUbiquitous:NO itemAtURL:localPathURL destinationURL:cloudPathURL error:&error]; 

,我得到以下錯誤:「該操作無法完成(李。 brarianErrorDomain錯誤2 - 無法在沒有同步的項目禁用同步)」

爲什麼這個錯誤發生的任何想法,我能如何擺脫它?我本來以爲我的文件完全同步...

提前感謝!

回答

2

我想通了。要禁用的iCloud同步,我卻意外地呼喚:中

[[NSFileManager defaultManager] setUbiquitous:NO itemAtURL:localPathURL destinationURL:cloudPathURL error:&error]; 

代替

[[NSFileManager defaultManager] setUbiquitous:NO itemAtURL:cloudPathURL destinationURL:localPathURL error:&error];