“访问钥匙串时发生错误”

Tal*_*rda 5 ios firebase swift firebase-authentication flutter

我为 Flutter 使用 Firebase Auth 插件以便在我的应用程序中使用 Google 登录,并且它在 iOS 和 Android 上都可以正常工作

当我尝试在我的 iOS“共享扩展”中使用 Firebase 身份验证时,我的问题就开始了。我是 iOS 新手,所以我不太熟悉 Swift 和 Xcode,但据我所知,我应该使用共享 iOS 钥匙串启用跨应用程序身份验证,以便在我的共享扩展中对用户进行身份验证。

我的项目中有 2 个目标,“Runner”和“Share Extension”,因此我为它们启用了钥匙串共享:

在此处输入图片说明

启用钥匙串共享后,当我尝试使用 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<…>
Run Code Online (Sandbox Code Playgroud)

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

SecItemCopyMatching (-34018)
Run Code Online (Sandbox Code Playgroud)

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


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

Tal*_*rda 3

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

Auth.auth().useUserAccessGroup("XK********.com.matkonit.SharedItems")
Run Code Online (Sandbox Code Playgroud)