2015-02-09 2 views
0

Это первый раз, когда я пытаюсь выполнить эту работу. Я после iCloud Programming Guide for Core Data, раздел «Использование SQLite магазин с ICloud», и в AppDelegate у меня есть:Как включить iCloud для данных ядра?

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator 
{ 
    // The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. 
    if (_persistentStoreCoordinator != nil) { 
     return _persistentStoreCoordinator; 
    } 

    // Create the coordinator and store 

    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; 
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"MyApp.sqlite"]; 
    NSError *error = nil; 
    NSString *failureReason = @"There was an error creating or loading the application's saved data."; 

    // To enable iCloud 
    NSDictionary *storeOptions = @{NSPersistentStoreUbiquitousContentNameKey: @"MyAppCloudStore"}; 

    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:storeOptions error:&error]) { 
     // Report any error we got. 
     NSMutableDictionary *dict = [NSMutableDictionary dictionary]; 
     dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data"; 
     dict[NSLocalizedFailureReasonErrorKey] = failureReason; 
     dict[NSUnderlyingErrorKey] = error; 
     error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict]; 
     // Replace this with code to handle the error appropriately. 
     // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    } 

    return _persistentStoreCoordinator; 
} 

Раньше я включил услуги ICloud для этого App ID, создайте соответствующую инициализацию и включите службы iCloud в возможностях Xcode (документы iCloud и контейнер по умолчанию).

Согласно iCloud Programming Guide for Core Data, на данный момент:

Тест: Запустите приложение на устройстве. Если Core Data успешно создала и настроила постоянное хранилище с поддержкой iCloud, среда регистрирует сообщение, содержащее «Использование локального хранилища: 1», а позднее другое сообщение, содержащее «Использование локального хранилища: 0».

Я запустил приложение на iPhone, и persistentStoreCoordinator извлекается, но я ничего не вижу в области отладки Xcode.

Что мне не хватает?

Спасибо?

ответ

0

Я нашел проблему: [[NSFileManager defaultManager] ubiquityIdentityToken] возвращался nil, и это было потому, что у меня было мое устройство не обновлено до iCloud Drive.

Я нашел ответ в this post.

Смежные вопросы