Get “No keychain available” error when try to access keychain from app extension

坚强是说给别人听的谎言 提交于 2019-12-02 00:36:03

问题


I am making a IOS custom keyboard extension. By default the keyboard has limited functionality, but when the user purchases the full version from the main parent app then the keyboard unlocks the missing parts.

To check if the user has purchased the app I try to store a Bool in the IOS keychain using this library.

    let IAPKeychain = Keychain(service: "com.roymunsonstudios.CopypastaKeyboard")

    var purchase: Bool = true
    let purchaseData = NSData(bytes: &purchase, length: sizeof(Bool))

    try! IAPKeychain.set(purchaseData, key: identifier)

I then try to access the keychain from my keyboard extension in the viewDidLoad method like this:

let IAPFetch = Keychain(service: "com.roymunsonstudios.CopypastaKeyboard.Copypasta")
print("Just finished creating keychain instance")
do {
        let purchaseStatusData = try IAPFetch.getData("com.roymunsonstudios.CopypastaKeyboard.FullVersionKeyboard")
}
catch is ErrorType {
print("Error fetching data")
}

However, whenever I try to do this I get the following error:

OSStatus error:[-25291] No keychain is available. You may need to restart your computer.

I am not sure what is wrong. I have turned on keychain sharing in the extension and the main app and I have the same keychain group name in each target (the keychain group name is the extension's bundle ID).

Why is this error occurring?

来源:https://stackoverflow.com/questions/38555764/get-no-keychain-available-error-when-try-to-access-keychain-from-app-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!