繁体   English   中英

ios键盘扩展中的Coredata

[英]Coredata in ios keyboard extension

我阅读下面的github页面并使用代码在我的ios Keyboard Extension和应用coredata之间共享coredata

https://github.com/maximbilan/iOS-Shared-CoreData-Storage-for-App-Groups

代码在模拟器上正常工作,但它不起作用,但addPersistentStore不能在真实设备上工作:

lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {
    // The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
    // Create the coordinator and store
    var coordinator: NSPersistentStoreCoordinator? = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)

    let directory = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier:"group.testKeyboard.asanpardakht.ir")!

    let url = directory.appendingPathComponent("AsanPardakhtSharedData.sqlite")

    do {
        try coordinator!.addPersistentStore(ofType: NSSQLiteStoreType, configurationName: nil, at: url, options: nil)
    } catch var error as NSError {
        coordinator = nil
        NSLog("Unresolved error \(error), \(error.userInfo)")
        abort()
    } catch {
        fatalError()
    }
    print("\(String(describing: coordinator?.persistentStores))")
    return coordinator
}()

我得到以下错误:

NSError域:“NSCocoaErrorDomain” - 代码:512

“reason”:“创建文件失败;代码= 1”

我尝试在我的info.plist文件中将RequestOpenAccess设置为YES ,但它仍然无法正常工作。 有人对此问题有任何想法吗?

我发现下面的帖子也适用于键盘扩展:

https://github.com/maximbilan/iOS-Shared-CoreData-Storage-for-App-Groups

唯一的问题是,对于键盘扩展,我们还应该将info.plist RequestOpenAccess设置为YES

当在键盘设置中将其设置为YES时,将显示Full Access选项,我们应将其打开,然后代码也适用于真实设备。

开发人员应确保在调用任务之前请求用户将选项设置为On。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM