2014-01-24 62 views
0

我想從plist預填充核心數據。得到了排序。無論如何,爲了不預先填充核心數據當iCloud擁有數據allrdy。我該如何檢查? 我使用魔法記錄來導入和處理我的Core Data + iCloud,它的工作原理如何檢查iCloud中是否有內容?核心數據

我想念某個地方或者我不知道。它會導入並檢查是否有值allrdy,如果它沒有導入。我希望 它在本地存儲工作,但只要我打開iCloud就會變得混亂

我發現這個,但它不適用於我。我不知道這是正確的做法 。有些我覺得我需要先檢查iCloud是否啓用,然後如果有內容或我在這裏完全錯誤?

NSURL *ubiq = [[NSFileManager defaultManager] 
        URLForUbiquityContainerIdentifier:nil]; 
    if (ubiq) { 
     NSLog(@"iCloud access at %@", ubiq); 
} 
else { 
NSlog(@"No iCloud") 
} 

回答

2

檢查:

- (BOOL) iCloudCheckContent{ 

    NSString* backupName = @"myBackup"; 
    NSError *error = nil; 
    NSFileManager *filemanager = [NSFileManager defaultManager];  
    NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; 

    if (ubiq == nil) { 
     NSlog(@"No iCloud"); 
     return NO; 
    } 

    bool ret = [filemanager startDownloadingUbiquitousItemAtURL:[[ubiq URLByAppendingPathComponent:@"Documents" isDirectory:true] URLByAppendingPathComponent:backupName] error:&error]; 

    NSLog(@"Started for %@ %d", backupName, ret); 

    if (error != nil) { 
     NSLog(@"iCloud error: %@", [error localizedDescription]); 
    } 

    return ret; 
}