project-imas / encrypted-core-data

v2.0 - iOS Core Data encrypted SQLite store using SQLCipher
Other
785 stars 236 forks source link

addPersistentStoreWithType:EncryptedStoreType don't work in XCode 8 #255

Closed ampilogov closed 7 years ago

ampilogov commented 7 years ago

I migrate to XCode 8 and have problems with NSPersistentStoreCoordinator initialisation

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (_persistentStoreCoordinator == nil)
    {
    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
        NSError *error = nil;
        NSDictionary *options = @{ EncryptedStorePassphraseKey : @"XXX", 
                                   NSMigratePersistentStoresAutomaticallyOption : [NSNumber numberWithBool:YES],
                                   NSInferMappingModelAutomaticallyOption : [NSNumber numberWithBool:YES]
                                   };

        if (![_persistentStoreCoordinator addPersistentStoreWithType:persistentStoreType configuration:nil URL:self.databaseURL options:options error:&error])
        {
            [[self class] removeSQLiteDBWithURL:self.databaseURL];

            MBLog(MBLogTypeDebug, (MBLogSourceFile | MBLogSourceConsole), @"%@ cleaned", self.databaseURL.absoluteString);

            _persistentStoreCoordinator = nil;
            dispatch_async(dispatch_get_main_queue(), ^{
                [self persistentStoreCoordinator];
            });
        }
    }

    return _persistentStoreCoordinator;
}

It worked good in XCode 7, but now it return nil

irezhko commented 7 years ago

Looks like it's not an issue. I've just fixed similar problem. https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-new-sdks/1688 I think in your case you use sqlite3_key of standard SDK but not of SQLCipher. status = sqlite3_key(database, string, (int)strlen(string)); EncryptedStore.m 914 Please make sure that you linked libsqlcipher correctly. For me it was enough just do not link sqlite3 library