Existing base database does not load in iCloud when iCloud is enabled in my application

I have a simple application in the App Store that is UITableViewwhich is populated by a user filling in some UITextFieldin a view called modally. The user clicks the "Save" button, and everything is saved in the "Basic data" and is NSFetchedResultsControllersupdated with the help UITableView.

Now I am updating my application to introduce synchronization iCloud(and the version of iPad).

I am new to development iCloud, and although the post that I am after http://goddess-gate.com/dc2/index.php/post/452 is several years old, it mainly works for me.

Problem

Without dwelling on other problems, the problem that I am facing now is that if I use the version of the App Store application for my application with some data (which do not have iCloud enabled) when I update my application using my development construct in Xcode, I expect my source data to still be there and therefore load in iCloud.

I do not have a checkbox in the application that does not load, but I will get to this. At the moment, the problem is that I start with a completely empty database when updating my application, although I suspect that this is just a problem with my code actually displaying the data now, because in the settings of my device it shows 9.7 KB data saved in iCloud (I had to delete iCloud backup data before doing this test).

I set up my application identifier on the developer portal by enabling iCloud and adjusting Xcode to enable this when creating a new SSL certificate in Developer and important new provisioning profiles in Xcode.

Update: a large number of changes have been made to my application and the removal of old code

App Delegate persistentStoreCoordinator: ( )

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Planner.sqlite"];
    NSError *error = nil;
    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    NSDictionary *options = @{
                              NSMigratePersistentStoresAutomaticallyOption : @YES,
                              NSInferMappingModelAutomaticallyOption : @YES
                              };
    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {

        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }

    NSPersistentStore *ps = [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error];

    NSFileManager *fm = [NSFileManager defaultManager];
    NSURL *url = [fm URLForUbiquityContainerIdentifier:nil];
    NSDictionary *iCloudOptions = @{
                              NSMigratePersistentStoresAutomaticallyOption : @YES,
                              NSInferMappingModelAutomaticallyOption : @YES,
                              NSPersistentStoreUbiquitousContentNameKey : @"EnvysStore"
                              };
    NSPersistentStore *store = [[_persistentStoreCoordinator persistentStores] firstObject];

    store = [_persistentStoreCoordinator migratePersistentStore:ps toURL:url options:iCloudOptions withType:NSSQLiteStoreType error:&error];

    return _persistentStoreCoordinator;
}

:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'nil is not a valid persistent store' on the 

    store = [_persistentStoreCoordinator migratePersistentStore:ps toURL:url options:iCloudOptions withType:NSSQLiteStoreType error:&error];

, , App Store , , , , , , .

!

+1
1

, , , , App Store ( iCloud ), , Xcode, , iCloud.

. Core Data iCloud . , . iCloud, , . , .

iCloud, , . - [NSPersistentStoreCoordinator migratePersistentStore:toURL:options:withType:error:], , . iCloud , , .

, . .

+3

Source: https://habr.com/ru/post/1540665/


All Articles