首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >颤振火基登录与苹果不工作的ios

颤振火基登录与苹果不工作的ios
EN

Stack Overflow用户
提问于 2021-10-29 13:17:56
回答 1查看 1.1K关注 0票数 0

我正在尝试用下面的代码建立苹果的登录。按按钮时什么都不会发生。

我得到以下错误:

代码语言:javascript
运行
复制
NoSuchMethodError (NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling: []("User"))

新用户出现在firebase身份验证中,但除此之外,该应用程序无法工作。

我在xcode和developer.apple.com上启用了苹果的登录功能。我也尝试过用xcode重新下载我的配置文件,但没有成功。

我已经在火炉里启用了苹果的登录。

有人知道怎么解决这个问题吗?

代码语言:javascript
运行
复制
mixin AuthenticationApple {
  static String generateNonce([int length = 32]) {
    const charset =
        '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
    final random = Random.secure();
    return List.generate(length, (_) => charset[random.nextInt(charset.length)])
        .join();
  }

  /// Returns the sha256 hash of [input] in hex notation.
  static String sha256ofString(String input) {
    final bytes = utf8.encode(input);
    final digest = sha256.convert(bytes);
    return digest.toString();
  }

  static Future<User> signInWithApple({BuildContext context}) async {
    User user;
    // To prevent replay attacks with the credential returned from Apple, we
    // include a nonce in the credential request. When signing in with
    // Firebase, the nonce in the id token returned by Apple, is expected to
    // match the sha256 hash of `rawNonce`.
    final rawNonce = generateNonce();
    final nonce = sha256ofString(rawNonce);

    // Request credential for the currently signed in Apple account.
    final appleCredential = await SignInWithApple.getAppleIDCredential(
      scopes: [
        AppleIDAuthorizationScopes.email,
        AppleIDAuthorizationScopes.fullName,
      ],
      nonce: nonce,
    );

    // Create an `OAuthCredential` from the credential returned by Apple.
    final oauthCredential = OAuthProvider('apple.com').credential(
      idToken: appleCredential.identityToken,
      rawNonce: rawNonce,
    );
    try {
      // Sign in the user with Firebase. If the nonce we generated earlier does
      // not match the nonce in `appleCredential.identityToken`, sign in will fail.
      final UserCredential userCredential =
          await FirebaseAuth.instance.signInWithCredential(oauthCredential);
      user = userCredential.user;
    } on FirebaseAuthException catch (e) {
      if (e.code == 'account-exists-with-different-credential') {
        ScaffoldMessenger.of(context).showSnackBar(
          AppWidget.customSnackBar(
            content: 'The account already exists with a different credential.',
          ),
        );
      } else if (e.code == 'invalid-credential') {
        ScaffoldMessenger.of(context).showSnackBar(
          AppWidget.customSnackBar(
            content: 'Error occurred while accessing credentials. Try again.',
          ),
        );
      }
    } catch (e) {
      ScaffoldMessenger.of(context).showSnackBar(
        AppWidget.customSnackBar(
          content: 'Error occurred using Apple Sign-In. Try again.',
        ),
      );
    }
    return user;
  }
}
EN

回答 1

Stack Overflow用户

发布于 2022-03-04 17:35:50

我刚刚超越了这个问题,使用iOS 13.0作为模拟器。在使用模拟器时,似乎存在高版本的问题,而物理设备没有问题。

您可以下载并安装模拟器,直到iOS 13.0 (这是苹果登录的最低版本)。在Xcode中:

Xcode > Preferences。选择"Components“选项卡。标记你想要的模拟器。按“检查并立即安装”。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69769564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档