锁匠错误:Locksmith.LocksmithError.interactionNotAllowed [英] Locksmith error: Locksmith.LocksmithError.interactionNotAllowed

查看:92
本文介绍了锁匠错误:Locksmith.LocksmithError.interactionNotAllowed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Locksmith来保存Keychain的用户数据.最后,一切正常,但由于某些原因,我们收到了崩溃,错误为Locksmith.LocksmithError.interactionNotAllowed.

we're using Locksmith to save user data for Keychain. In our end everything works as it should but for some reason we receive crashes with the error Locksmith.LocksmithError.interactionNotAllowed.

遵循发生崩溃的代码:

func updateUserAccessToken(forAccount account: String, token: String) {
    var userAccessToken = Locksmith.loadDataForUserAccount(userAccount: account) ?? [String: Any]()
    userAccessToken["token"] = token
    try! Locksmith.updateData(data: userAccessToken, forUserAccount: account)
}

为什么上面的代码对其他用户崩溃?直到.现在我们无法复制上述崩溃.很感谢任何形式的帮助.谢谢!

Why is the code above crashes for other users? 'til . now we can't replicate the said crash. Any help is very much appreciated. Thanks!

更新: 因此,我们最终能够复制此崩溃,这是因为我们正在锁定设备的同时访问钥匙串.我发现您可以更改钥匙串的可访问性选项",但是我不确定如何在Locksmith中进行操作.有人吗?

UPDATE: So we finally able to replicate this crash, and it's because we're accessing the keychain while the device is locked. I found out you can change the Keychain's "accessibility option" but I'm not sure how to do it in Locksmith. Anybody?

推荐答案

我发现,如果您使用的是协议基础方法,则更改可访问性选项更容易.但是很遗憾,我们的应用程序未使用它.所以我要做的就是创建一个扩展,如下所示:

I found out that if you're using a protocol base approach changing the accessibility option is much more easier. But unfortunately our app doesn't use it. So what I did was I created an extension as follow:

extension Locksmith {
    fileprivate static func loadDataForUserAccount(userAccount: String,
                                                   inService service: String = LocksmithDefaultService,
                                                   accessibleOption: LocksmithAccessibleOption) -> [String: Any]? {
        struct ReadRequest: GenericPasswordSecureStorable, ReadableSecureStorable {
            let service: String
            let account: String
            var accessible: LocksmithAccessibleOption?
        }

        let request = ReadRequest(service: service, account: userAccount, accessible: accessibleOption)
        return request.readFromSecureStore()?.data
    }

    fileprivate static func updateData(data: [String: Any],
                                       forUserAccount userAccount: String,
                                       inService service: String = LocksmithDefaultService,
                                       accessibleOption: LocksmithAccessibleOption) throws {

        struct UpdateRequest: GenericPasswordSecureStorable, CreateableSecureStorable {
            let service: String
            let account: String
            let data: [String: Any]
            var accessible: LocksmithAccessibleOption?
        }

        let request = UpdateRequest(service: service, account: userAccount, data: data, accessible: accessibleOption)
        return try request.updateInSecureStore()
    }
}

注意::更改可访问性选项" 可能会使您无法访问以前使用默认可访问性选项" 保存的数据.如果需要这些数据,则可能需要单独处理.

NOTE: changing the "accessibility option" may loss your access to the data previously saved with the default "accessibility option". If you need those data you may need to handle it separately.

这篇关于锁匠错误:Locksmith.LocksmithError.interactionNotAllowed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆