Google 登录 Xcode 时出现错误 Sigabrt
Error Sigabrt with Google Sign In Xcode
我在构建 AppDelegate 文件时遇到错误,这是一个 sigabrt 错误。我已经阅读了许多关于 sigabrt 的其他主题,但我想问的是如何修复此 sigabrt 错误,因为它与 Google 登录有何关系。
ViewController.swift代码:
import UIKit
import GoogleSignIn
import Firebase
class ViewController: UIViewController, GIDSignInUIDelegate {
override func viewDidLoad() {
super.viewDidLoad()
setupGoogleButtons()
}
fileprivate func setupGoogleButtons(){
//default google sign in button
let googleButton = GIDSignInButton()
googleButton.frame = CGRect(x: 16, y: 116 + 80, width: view.frame.width - 32, height: 50)
view.addSubview(googleButton)
//custom google sign in button
let customButton = UIButton(type: .system)
customButton.frame = CGRect(x: 16, y: 116 + 80 + 66, width: view.frame.width - 32, height: 50)
customButton.backgroundColor = .blue
customButton.setTitleColor(.white, for: .normal)
customButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
customButton.setTitle("Google Sign In #2", for: .normal)
customButton.addTarget(self, action: #selector(handleCustomGoogleSignIn), for: .touchUpInside)
view.addSubview(customButton)
}
func handleCustomGoogleSignIn() {
GIDSignIn.sharedInstance().signIn()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
AppDelegate 文件代码:
import UIKit
import Firebase
import GoogleSignIn
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
return true
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let err = error {
print("Failed to log into Google: ", err)
return
}
print("Successfully logged into Google", user)
guard let idToken = user.authentication.idToken else { return }
guard let accessToken = user.authentication.accessToken else { return }
let credentials = FIRGoogleAuthProvider.credential(withIDToken: idToken, accessToken: accessToken)
FIRAuth.auth()?.signIn(with: credentials, completion: { (user, error) in
if let err = error {
print("Failed to create a Firebase User with Google account: ", err)
return
}
guard let uid = user?.uid else { return }
print("Successfully logged into Firebase with Google", uid)
})
}
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
GIDSignIn.sharedInstance().handle(url,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
return true
}
}
控制台错误消息:
objc[12677]: Class PLBuildVersion 在 /Users/tarunaarora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x119012998) 和 /Users/tarunaarora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x118e34880)。将使用两者之一。哪一个是未定义的。
2016-11-21 21:44:27.647 GunnOracleGoogleSignIn[12677:470666] 启用 Firebase 自动屏幕报告。调用 +[FIRAnalytics setScreenName:setScreenClass:] 设置屏幕名称或覆盖默认屏幕 class 名称。要禁用自动屏幕报告,请在 Info.plist 中将标志 FirebaseAutomaticScreenReportingEnabled 设置为 NO
2016-11-21 21:44:27.929: FIRInstanceID AppDelegate 代理已启用,将 swizzle 应用委托远程通知处理程序。要禁用将 "FirebaseAppDelegateProxyEnabled" 添加到您的 Info.plist 并将其设置为 NO
2016-11-21 21:44:27.928 GunnOracleGoogleSignIn[12677] [Firebase/Core][I-COR000001] 配置默认应用程序。
2016-11-21 21:44:28.330 GunnOracleGoogleSignIn[12677:] Firebase Analytics v.3501000 启动
2016-11-21 21:44:28.542 GunnOracleGoogleSignIn[12677:] 要启用调试日志记录,请设置以下应用程序参数:-FIRAnalyticsDebugEnabled(请参阅(google url//不能显示因为是goo.gl))
2016-11-21 21:44:28.637 GunnOracleGoogleSignIn[12677:] 自动成功创建 Firebase Analytics 应用程序委托代理。要禁用代理,请在 Info.plist 中将标志 FirebaseAppDelegateProxyEnabled 设置为 NO
2016-11-21 21:44:28.782 GunnOracleGoogleSignIn[12677] <调试> [Firebase/Core][I-COR000019] 清除 post 完成。
2016-11-21 21:44:30.143 GunnOracleGoogleSignIn[12677:] 当前未链接 AdSupport 框架。某些功能将无法正常运行。了解更多信息(无法显示 goo.gl url)
2016-11-21 21:44:31.086 GunnOracleGoogleSignIn[12677:] 启用 Firebase 分析
2016-11-21 21:44:31.841 GunnOracleGoogleSignIn[12677:470666] *** 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'uiDelegate must either be a |UIViewController| or implement the |signIn:presentViewController:| and |signIn:dismissViewController:| methods from |GIDSignInUIDelegate|.'
*** 首先抛出调用栈:
(
0 核心基础 0x00000001076ffd4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010716121e objc_exception_throw + 48
2 CoreFoundation 0x00000001077692b5 +[NSException raise:format:] + 197
3 GunnOracleGoogle登录 0x000000010619df7e -[GIDSignIn signInWithOptions:] + 88
4 GunnOracleGoogle登录 0x00000001061a1c13 -[GIDSignInButton 按下] + 242
5 UIKit 0x000000010823845c -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x00000001083be344 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00000001083be65d -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x00000001083bd559 -[UIControl touchesEnded:withEvent:] + 668
9 UIKit 0x00000001082a5d5d -[UIWindow _sendTouchesForEvent:] + 2747
10 UIKit 0x00000001082a744b -[UIWindow 发送事件:] + 4011
11 UIKit 0x000000010825454b -[UIApplication sendEvent:] + 371
12 UIKit 0x0000000108a3fa0f __dispatchPreprocessedEventFromEventQueue + 3248
13 UIKit 0x0000000108a38745 __handleEventQueue + 4879
14 核心基础 0x00000001076a48e1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 核心基础 0x0000000107689b0c __CFRunLoopDoSources0 + 556
16 核心基础 0x0000000107688ff6 __CFRunLoopRun + 918
17 核心基础 0x0000000107688a04 CFRunLoopRunSpecific + 420
18 图形服务 0x000000010bad6a6f GSEventRunModal + 161
19 UIKit 0x0000000108236808 UIApplicationMain + 159
20 GunnOracleGoogle登录 0x00000001060f669f main + 111
21 libdyld.dylib 0x000000010a4a368d 开始 + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib:以 NSException 类型的未捕获异常终止
如果还有其他需要包括的内容,请告诉我。
在我的例子中,原因是这个错误:
Unable to correctly configure subspec Analytics
通过将正确的跟踪 ID 设置为 GoogleService-Info.plist
可以解决此问题。有关详细信息,请参阅:
我在构建 AppDelegate 文件时遇到错误,这是一个 sigabrt 错误。我已经阅读了许多关于 sigabrt 的其他主题,但我想问的是如何修复此 sigabrt 错误,因为它与 Google 登录有何关系。
ViewController.swift代码:
import UIKit
import GoogleSignIn
import Firebase
class ViewController: UIViewController, GIDSignInUIDelegate {
override func viewDidLoad() {
super.viewDidLoad()
setupGoogleButtons()
}
fileprivate func setupGoogleButtons(){
//default google sign in button
let googleButton = GIDSignInButton()
googleButton.frame = CGRect(x: 16, y: 116 + 80, width: view.frame.width - 32, height: 50)
view.addSubview(googleButton)
//custom google sign in button
let customButton = UIButton(type: .system)
customButton.frame = CGRect(x: 16, y: 116 + 80 + 66, width: view.frame.width - 32, height: 50)
customButton.backgroundColor = .blue
customButton.setTitleColor(.white, for: .normal)
customButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
customButton.setTitle("Google Sign In #2", for: .normal)
customButton.addTarget(self, action: #selector(handleCustomGoogleSignIn), for: .touchUpInside)
view.addSubview(customButton)
}
func handleCustomGoogleSignIn() {
GIDSignIn.sharedInstance().signIn()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
AppDelegate 文件代码:
import UIKit
import Firebase
import GoogleSignIn
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
return true
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if let err = error {
print("Failed to log into Google: ", err)
return
}
print("Successfully logged into Google", user)
guard let idToken = user.authentication.idToken else { return }
guard let accessToken = user.authentication.accessToken else { return }
let credentials = FIRGoogleAuthProvider.credential(withIDToken: idToken, accessToken: accessToken)
FIRAuth.auth()?.signIn(with: credentials, completion: { (user, error) in
if let err = error {
print("Failed to create a Firebase User with Google account: ", err)
return
}
guard let uid = user?.uid else { return }
print("Successfully logged into Firebase with Google", uid)
})
}
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
GIDSignIn.sharedInstance().handle(url,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
return true
}
}
控制台错误消息:
objc[12677]: Class PLBuildVersion 在 /Users/tarunaarora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x119012998) 和 /Users/tarunaarora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x118e34880)。将使用两者之一。哪一个是未定义的。 2016-11-21 21:44:27.647 GunnOracleGoogleSignIn[12677:470666] 启用 Firebase 自动屏幕报告。调用 +[FIRAnalytics setScreenName:setScreenClass:] 设置屏幕名称或覆盖默认屏幕 class 名称。要禁用自动屏幕报告,请在 Info.plist 中将标志 FirebaseAutomaticScreenReportingEnabled 设置为 NO 2016-11-21 21:44:27.929:FIRInstanceID AppDelegate 代理已启用,将 swizzle 应用委托远程通知处理程序。要禁用将 "FirebaseAppDelegateProxyEnabled" 添加到您的 Info.plist 并将其设置为 NO 2016-11-21 21:44:27.928 GunnOracleGoogleSignIn[12677] [Firebase/Core][I-COR000001] 配置默认应用程序。 2016-11-21 21:44:28.330 GunnOracleGoogleSignIn[12677:] Firebase Analytics v.3501000 启动 2016-11-21 21:44:28.542 GunnOracleGoogleSignIn[12677:] 要启用调试日志记录,请设置以下应用程序参数:-FIRAnalyticsDebugEnabled(请参阅(google url//不能显示因为是goo.gl)) 2016-11-21 21:44:28.637 GunnOracleGoogleSignIn[12677:] 自动成功创建 Firebase Analytics 应用程序委托代理。要禁用代理,请在 Info.plist 中将标志 FirebaseAppDelegateProxyEnabled 设置为 NO 2016-11-21 21:44:28.782 GunnOracleGoogleSignIn[12677] <调试> [Firebase/Core][I-COR000019] 清除 post 完成。 2016-11-21 21:44:30.143 GunnOracleGoogleSignIn[12677:] 当前未链接 AdSupport 框架。某些功能将无法正常运行。了解更多信息(无法显示 goo.gl url) 2016-11-21 21:44:31.086 GunnOracleGoogleSignIn[12677:] 启用 Firebase 分析 2016-11-21 21:44:31.841 GunnOracleGoogleSignIn[12677:470666] *** 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因:'uiDelegate must either be a |UIViewController| or implement the |signIn:presentViewController:| and |signIn:dismissViewController:| methods from |GIDSignInUIDelegate|.' *** 首先抛出调用栈: ( 0 核心基础 0x00000001076ffd4b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010716121e objc_exception_throw + 48 2 CoreFoundation 0x00000001077692b5 +[NSException raise:format:] + 197 3 GunnOracleGoogle登录 0x000000010619df7e -[GIDSignIn signInWithOptions:] + 88 4 GunnOracleGoogle登录 0x00000001061a1c13 -[GIDSignInButton 按下] + 242 5 UIKit 0x000000010823845c -[UIApplication sendAction:to:from:forEvent:] + 83 6 UIKit 0x00000001083be344 -[UIControl sendAction:to:forEvent:] + 67 7 UIKit 0x00000001083be65d -[UIControl _sendActionsForEvents:withEvent:] + 444 8 UIKit 0x00000001083bd559 -[UIControl touchesEnded:withEvent:] + 668 9 UIKit 0x00000001082a5d5d -[UIWindow _sendTouchesForEvent:] + 2747 10 UIKit 0x00000001082a744b -[UIWindow 发送事件:] + 4011 11 UIKit 0x000000010825454b -[UIApplication sendEvent:] + 371 12 UIKit 0x0000000108a3fa0f __dispatchPreprocessedEventFromEventQueue + 3248 13 UIKit 0x0000000108a38745 __handleEventQueue + 4879 14 核心基础 0x00000001076a48e1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 15 核心基础 0x0000000107689b0c __CFRunLoopDoSources0 + 556 16 核心基础 0x0000000107688ff6 __CFRunLoopRun + 918 17 核心基础 0x0000000107688a04 CFRunLoopRunSpecific + 420 18 图形服务 0x000000010bad6a6f GSEventRunModal + 161 19 UIKit 0x0000000108236808 UIApplicationMain + 159 20 GunnOracleGoogle登录 0x00000001060f669f main + 111 21 libdyld.dylib 0x000000010a4a368d 开始 + 1 22 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib:以 NSException 类型的未捕获异常终止
如果还有其他需要包括的内容,请告诉我。
在我的例子中,原因是这个错误:
Unable to correctly configure subspec Analytics
通过将正确的跟踪 ID 设置为 GoogleService-Info.plist
可以解决此问题。有关详细信息,请参阅: