ios - GIDSignInButton - 以 NSException 类型的未捕获异常终止

标签 ios iphone swift xcode google-signin

在使用 GIDSignInBUtton 类单击 View 时,我不断收到 libc++abi.dylib: terminating with uncaught exception of type NSException 错误。有没有人以前遇到过这个问题或有使用 Google Sign In API 的经验可以帮助我?

这是我的代码:

import UIKit
import Google
import GoogleSignIn

@UIApplicationMain
// [START appdelegate_interfaces]
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {

    // [END appdelegate_interfaces]
    var window: UIWindow?

    // [START didfinishlaunching]
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Initialize sign-in
        var configureError: NSError?
        GGLContext.sharedInstance().configureWithError(&configureError)
        assert(configureError == nil, "Error configuring Google services: \(configureError)")

        GIDSignIn.sharedInstance().delegate = self

        return true
    }
    // [END didfinishlaunching]
    // [START openurl]
    func application(_ application: UIApplication,
                     open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        return GIDSignIn.sharedInstance().handle(url,
                                                 sourceApplication: sourceApplication,
                                                 annotation: annotation)
    }
    // [END openurl]
    @available(iOS 9.0, *)
    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
        return GIDSignIn.sharedInstance().handle(url,
                                                 sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                 annotation: options[UIApplicationOpenURLOptionsKey.annotation])
    }

    // [START signin_handler]
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
              withError error: Error!) {
        if let error = error {
            print("\(error.localizedDescription)")
            // [START_EXCLUDE silent]
            NotificationCenter.default.post(
                name: Notification.Name(rawValue: "ToggleAuthUINotification"), object: nil, userInfo: nil)
            // [END_EXCLUDE]
        } else {
            // Perform any operations on signed in user here.
            let userId = user.userID                  // For client-side use only!
            let idToken = user.authentication.idToken // Safe to send to the server
            let fullName = user.profile.name
            let givenName = user.profile.givenName
            let familyName = user.profile.familyName
            let email = user.profile.email
            // [START_EXCLUDE]
            NotificationCenter.default.post(
                name: Notification.Name(rawValue: "ToggleAuthUINotification"),
                object: nil,
                userInfo: ["statusText": "Signed in user:\n\(fullName)"])
            // [END_EXCLUDE]
        }
    }
    // [END signin_handler]
    // [START disconnect_handler]
    func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!,
              withError error: Error!) {
        // Perform any operations when the user disconnects from app here.
        // [START_EXCLUDE]
        NotificationCenter.default.post(
            name: Notification.Name(rawValue: "ToggleAuthUINotification"),
            object: nil,
            userInfo: ["statusText": "User has disconnected."])
        // [END_EXCLUDE]
    }
    // [END disconnect_handler]
}

最佳答案

已修复!

探索源文件和 .plist 文件数小时后,我发现我错误地将 GoogleService-Info.plist 中的 CLIENT_ID 而不是 URL 类型中的 REVERSED_CLIENT_ID。

  • TARGET(右键单击您的项目)

  • 信息

  • URL 类型(输入 REVERSED_CLIENT_ID 而不是 CLIENT_ID)

它奏效了。 希望这会有所帮助。

关于ios - GIDSignInButton - 以 NSException 类型的未捕获异常终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42615204/

相关文章:

ios - 确保单例属性无法通过其他实例访问

ios - 在 Swift 中下载数据时如何不阻塞 UI

ios - 在 ios 上混合音频

ios - 为什么我的 NSTimer 在到期时不调用我的方法?

ios - 在联系人应用程序中重新创建 ipad 搜索栏

iphone - 更改任何单元格名称时顶部单元格名称也会更改

ios - Adobe Air IOS 中的黑色边框

iphone - 输入带小数点的数值的最佳方法是什么?

iphone - 随着用户拉动,UITableView 中的标题不断增加

ios - 如何在 SWIFT 中将词典添加到 Plist