【问题标题】:iOS Magical Record & SQLCipheriOS 魔法记录 & SQLCipher
【发布时间】:2013-08-24 07:03:40
【问题描述】:

我正在使用 Magical Record 来保存我的数据。该数据需要加密,因此我尝试将其与 SQLCipher 库(http://sqlcipher.net/ios-tutorial/)结合使用。

我已经设置了 SQLCipher 并使用 Core Data 成功地对其进行了测试,使用此示例中的 EncryptedStore 文件https://github.com/project-imas/encrypted-core-data

我所做的只是像这样更改 NSPersistentStoreCoordinator:

NSPersistentStoreCoordinator *coordinator = [EncryptedStore makeStore:[self managedObjectModel]:[SSKeychain passwordForService:myservice account:myaccount]];

所以我认为我需要更改在 MagicalRecord 中创建 NSPersistentStoreCoordinator 的方式,但我没有运气,因此将不胜感激。

【问题讨论】:

    标签: iphone ios magicalrecord sqlcipher


    【解决方案1】:

    如果您已经有一个持久存储协调器,则在使用 MagicalRecord 时必须手动设置核心数据堆栈。我推荐一些类似的东西:

     NSPersistentStoreCoordinator *coordinator = //how ever you do it;
     [NSPersistentStoreCoordinator MR_setDefaultCoordinator:coordinator];
     [NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:coordinator];
    

    您可能需要自己公开初始化方法。

    作为旁注,您可能需要向 MagicalRecord 问题日志添加票证,以向 setup 方法集合添加方法以指定您自己的协调器,以便由 MagicalRecord 自己处理这项工作。

    【讨论】:

    • 我自己已经解决了这个问题。我一步一步通过 Magical Record 并在 NSPersistentStoreCoordinator+MagicalRecord.m 方法中进行了更改:+ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName withOptions:(NSDictionary *)options 差异:NSPersistentStoreCoordinator *psc = [EncryptedStore makeStore:model:@ “温度”]; // NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];现在 SQLCipher 可与 MagicalRecord 一起使用
    • 是的,你可能应该以“公共 api”的方式来做。如果您很擅长使用自定义更改来维护库,那就太好了。
    • @user1041311 您能否使用适合您的确切设置添加答案?
    猜你喜欢
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 2013-03-16
    相关资源
    最近更新 更多