“访问钥匙串时出错”

Posted

技术标签:

【中文标题】“访问钥匙串时出错”【英文标题】:"An error occurred when accessing the keychain" 【发布时间】:2020-06-20 19:39:41 【问题描述】:

我使用 Flutter 的 Firebase Auth 插件在我的应用中使用 Google 登录,它在 iOS 和 Android 中都可以正常工作

当我尝试在我的 ios“共享扩展”中使用 Firebase 身份验证时,我的问题就开始了。我是 iOS 新手,所以我不太熟悉 Swift 和 Xcode,但据我了解,我应该 enable cross-app authentication with shared iOS Keychain 以便在我的共享扩展中验证用户。

我的项目中有 2 个目标,“Runner”和“Share Extension”,所以我为它们都启用了 Keychain Sharing:

启用钥匙串共享后,我在尝试使用 Firebase 身份验证登录时收到以下错误:

Unhandled Exception: PlatformException(ERROR_KEYCHAIN_ERROR, An error occurred when accessing the keychain. The @c NSLocalizedFailureReasonErrorKey field in the @c NSError.userInfo dictionary will contain more information about the error encountered, null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
<asynchronous suspension>
#2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:349:48)
#3      MethodChannelFirebaseAuth.signInWithCredential (package:firebase_auth_platform_interface/src/method_channel_firebase_auth.dart:161:23)
#4      FirebaseAuth.signInWithCredential (package:firebase_auth/src/firebase_auth.dart:208:10)
#5      signInWithGoogle (package:matkonit/google_sign_in.dart:17:45)
<asynchronous suspension>
#6      LoginPageState.signInButton.<anonymous closure>.<anonymous clo<…>

这是我打印 NSLocalizedFailureReasonErrorKey 时得到的结果:

SecItemCopyMatching (-34018)

我该怎么做才能解决这个问题?


编辑:我注意到重新启动模拟器可以使登录工作,但只是有时......我不知道为什么。

【问题讨论】:

在 Stack Overflow 上仅供参考,反引号用于代码位,不用于标记产品名称和术语。 【参考方案1】:

我没有在我的 App ID 之前添加团队 ID 前缀,所以它不起作用。您需要拥有 Apple 开发者帐户和团队 ID 才能执行此操作,如下所示:

Auth.auth().useUserAccessGroup("XK********.com.matkonit.SharedItems")

【讨论】:

以上是关于“访问钥匙串时出错”的主要内容,如果未能解决你的问题,请参考以下文章

苹果密码钥匙串在哪里

MacBook钥匙串怎么关闭

想使用登录钥匙串卡死

Mac钥匙串有啥用?钥匙串访问是啥

钥匙串代码签名权利 - 奇怪的行为,钥匙串丢失

iOS 钥匙串服务与 iCloud 钥匙串不同吗?