锁匠错误:Locksmith.LocksmithError.interactionNotAllowed

时间:2018-01-23 04:23:58

标签: swift4 keychain

我们使用Locksmith来保存Keychain的用户数据。在我们最终,一切都按预期工作但由于某种原因我们收到错误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)
}

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

更新 所以我们终于能够复制这次崩溃了,这是因为我们在设备锁定时访问了钥匙串。我发现你可以改变Keychain的“辅助功能选项”,但我不知道如何在Locksmith中做到这一点。任何人

1 个答案:

答案 0 :(得分:1)

我发现,如果您使用协议库方法,则更改辅助功能选项会更容易。但遗憾的是我们的应用程序并没有使用它。所以我做的是我创建了一个扩展如下:

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()
    }
}

注意:更改"辅助功能选项" 可能会失去您之前使用默认"辅助功能保存的数据的访问权限选项" 。如果您需要这些数据,则可能需要单独处理。