【问题标题】:Firebase Auth failed on iOS (Unity, Xcode)iOS 上的 Firebase 身份验证失败(Unity、Xcode)
【发布时间】:2020-05-22 05:55:52
【问题描述】:

我正在尝试让 Firebase Unity SDK 在 iOS 13 设备上运行。我能够构建项目,但问题是我无法注册或验证用户。

复制步骤:(我做了什么)

  1. 已下载 quickstart-unity/auth/testapp 项目
  2. 在 iOS 平台的 Unity 2019.2.20f1 中打开
  3. 将 Bundle ID 更改为我在 Firebase 控制台中注册的那个
  4. 将 GoogleService-Info.plist 放在 Assets/Firebase 文件夹下
  5. Set Resolver iOS 设置选项将 CocoaPods 添加到 Xcode 项目
  6. 将最新的 Firebase Auth 包 6.10.0 从 dotnet4 文件夹导入到项目中
  7. 已构建

我在 Xcode 项目中看到的:

  1. PodFile 内容如下所示:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'

target 'Unity-iPhone' do
  pod 'Firebase/Auth', '6.14.0'
  pod 'Firebase/Core', '6.14.0'
end
  1. GoogleService-Info.plist 也在 Xcode 项目层次结构中

在装有 iOS 13 的 iPhone 8 上签名并构建。

结果:当我尝试填写字段电子邮件和密码并按下调用该方法的“创建用户”按钮时:

// Create a user with the email and password.
    public Task CreateUserWithEmailAsync() {
      DebugLog(String.Format("Attempting to create user {0}...", email));
      DisableUI();

      // This passes the current displayName through to HandleCreateUserAsync
      // so that it can be passed to UpdateUserProfile().  displayName will be
      // reset by AuthStateChanged() when the new user is created and signed in.
      string newDisplayName = displayName;
      return auth.CreateUserWithEmailAndPasswordAsync(email, password)
        .ContinueWithOnMainThread((task) => {
          EnableUI();
          if (LogTaskCompletion(task, "User Creation")) {
            var user = task.Result;
            DisplayDetailedUserInfo(user, 1);
            return UpdateUserProfileAsync(newDisplayName: newDisplayName);
          }
          return task;
        }).Unwrap();
    }

我在设备屏幕和 Xcode 日志中也看到了这个错误:

AuthError.Failure: Firebase.FirebaseException: An internal error has occurred, print and inspect the error details for more information.

这是来自 Xcode 的完整日志:

https://drive.google.com/file/d/1ZQzrA67NXqM-lwNsSqT8Dgam9XiSHD9y/view?usp=sharing

我也尝试过:

  1. 在 iOS 版本较低的设备上构建。
  2. 尝试使用 Unity 2019.1.11 和 2019.1.13 版本构建
  3. 尝试将 GoogleService-Info.plist 直接导入 Xcode 项目
  4. 已试用 Firebase SDK 6.8.0 版本
  5. 尝试手动添加 [FIRApp 配置]
  6. 没有任何效果。

为项目配置的 Firebase 控制台,包含两个具有不同 Bundle ID 的应用 android 和 iOS。安卓版经过多次测试完美运行。

Unity 编辑器版本:2019.2.20f1

Firebase Unity SDK 版本:6.10.0

正在使用的 Firebase 插件:身份验证

我们正在使用的其他 SDK(Facebook、AdMob 等):无

我们使用 Unity 编辑器的平台:Mac

我们的目标平台:iOS

脚本运行时:IL2CPP

Xcode 版本:11(最新)
CocoaPods:最新版本

【问题讨论】:

    标签: ios xcode firebase unity3d authentication


    【解决方案1】:

    至少我能够解决问题。这是我如何修复它的描述。

    正如我上面提到的,Unity 是这样导出 PodFile 的:

    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '9.0'
    
    target 'Unity-iPhone' do
      pod 'Firebase/Auth', '6.14.0'
      pod 'Firebase/Core', '6.14.0'
    end
    

    这意味着 Firebase Unity SDK 6.10.0 需要 Pod 版本 6.14.0。 使用这个 pod 构建时,我看到了上面提到的错误:

    [SA LOG] CreateUserWithEmailAndPasswordAsync encountered an error: System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> Firebase.FirebaseException: An internal error has occurred, print and inspect the error details for more information.
       --- End of inner exception stack trace ---
       --- End of inner exception stack trace ---
    ---> (Inner Exception #0) System.AggregateException: One or more errors occurred. ---> Firebase.FirebaseException: An internal error has occurred, print and inspect the error details for more information.
       --- End of inner exception stack trace ---
    ---> (Inner Exception #0) Firebase.FirebaseException: An internal error has occurred, print and inspect the error details for more information.<---
    <---
    

    正如你所见,这个错误什么也没说。

    经过长时间的研究,我注意到在 CocoaPods 网站上有更新的 Firebase pod 版本可用,所以我手动更改了我的 PodsFile 并使用终端安装了 Pod:

    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '9.0'
    
    target 'Unity-iPhone' do
      pod 'FirebaseAnalytics', '~> 6.2'
      pod 'FirebaseAuth', '~> 6.4'
      pod 'FirebaseCore', '~> 6.6'
    end
    

    在构建之后,我得到了人类可读的错误,上面写着:

    Response body: {
      "error": {
        "code": 400,
        "message": "API key expired. Please renew the API key.",
        "status": "INVALID_ARGUMENT",
        "details": [
          {
            "@type": "type.googleapis.com/google.rpc.Help",
            "links": [
              {
                "description": "Google developer console API key",
                "url": "https://console.developers.google.com/project/37062923653/apiui/credential"
              }
            ]
          }
        ]
      }
    }
    

    我按照错误提示在 Google Developer Console 中更新了 API 密钥,现在一切正常。

    结论:

    这与 Firebase Unity SDK 6.10.0 和 6.8.0 无关,也与 Parse DLL 无关。只是问题是 Firebase Pods 的旧版本 6.14.0 没有给出人类可读的错误,所以我无法理解发生了什么。使用最新的 Firebase Pod 后,我能够理解错误原因。

    感谢所有回复我问题的人。

    【讨论】:

      【解决方案2】:

      您需要检查您的 Xcode Info.Plist 文件,那里需要添加用于 google 登录的密钥。 Link

      还看到您的日志第 3 行需要删除一个键。

      【讨论】:

      • 感谢您的回复。在这个项目中,我只使用电子邮件和密码登录功能,我是否需要为 Google 登录添加密钥?还有我日志中的第 3 行,你是说这个吗?要禁用屏幕报告,请在 Info.plist 中将标志 FirebaseScreenReportingEnabled 设置为 NO(布尔值)
      • 是的,您需要添加密钥,同时为 FirebaseScreenReportingEnabled 密钥设置 NO
      • 链接已经存在 Unity 自动添加了它。在 Info.plist 中将标志 FirebaseScreenReportingEnabled 设置为 NO(布尔值)也无济于事。
      【解决方案3】:

      我看到“CreateUserWithEmailAndPasswordAsync 遇到错误:System.AggregateException:发生内部错误。”在 Unity 控制台中。

      为了解决这个问题,我关闭了 Unity,提交了我的重要更改,然后重新打开了 Unity。在出现的弹出窗口中,我单击了“启用”。

      同时,我还进入了 Firebase 控制台 (https://console.firebase.google.com/project/myprojectname/authentication/providers) 中的项目设置并启用了邮件注册。视频教程中也建议这样做,但书面教程中没有。 Firebase Official Video Tutorial

      之后,问题就解决了。

      【讨论】:

        猜你喜欢
        • 2020-05-22
        • 1970-01-01
        • 2017-11-27
        • 1970-01-01
        • 2019-03-09
        • 1970-01-01
        • 2017-08-24
        • 1970-01-01
        相关资源
        最近更新 更多