【问题标题】:How to check if there's content in iCloud ? Core Data如何检查 iCloud 中是否有内容?核心数据
【发布时间】:2014-01-24 17:58:37
【问题描述】:

我想从 plist 中预填充核心数据。得到了排序。无论如何,当 iCloud 有数据时,不要预填充核心数据。我该如何检查? 我正在使用 Magical Record 导入和处理我的 Core Data+iCloud,它可以工作

要么我错过了某处的某个步骤,要么我不知道。它导入并检查是否有值 allrdy 如果有它不导入。我希望 它可以在本地存储中运行,但是一旦我打开 iCloud,它就会变得一团糟

我找到了这个,但它对我不起作用。我不确定这是不是正确的方法 .我认为我需要先检查是否启用了 iCloud,然后检查是否有内容,或者我在这里完全错了?

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

【问题讨论】:

    标签: ios objective-c core-data icloud magicalrecord


    【解决方案1】:

    检查:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-24
      • 2015-11-11
      • 2013-06-03
      • 1970-01-01
      相关资源
      最近更新 更多