在使用 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/