2016-11-22 120 views
1

我遇到了一個錯誤,建立在一個sigabrt錯誤的AppDelegate文件。我已經閱讀過很多關於sigabrt的其他主題,但是我正在問如何解決這個sigabrt錯誤,因爲它與Google Sign In有關。錯誤Sigabrt與谷歌登錄Xcode

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 is implemented in both /Users/tarunaarora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x119012998) and /Users/tarunaarora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x118e34880). One of the two will be used. Which one is undefined. 
2016-11-21 21:44:27.647 GunnOracleGoogleSignIn[12677:470666] Firebase automatic screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO in the Info.plist 
2016-11-21 21:44:27.929: <FIRInstanceID/WARNING> FIRInstanceID AppDelegate proxy enabled, will swizzle app delegate remote notification handlers. To disable add "FirebaseAppDelegateProxyEnabled" to your Info.plist and set it to NO 
2016-11-21 21:44:27.928 GunnOracleGoogleSignIn[12677] <Debug> [Firebase/Core][I-COR000001] Configuring the default app. 
2016-11-21 21:44:28.330 GunnOracleGoogleSignIn[12677:] <FIRAnalytics/INFO> Firebase Analytics v.3501000 started 
2016-11-21 21:44:28.542 GunnOracleGoogleSignIn[12677:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see (google url//can't show because it is goo.gl)) 
2016-11-21 21:44:28.637 GunnOracleGoogleSignIn[12677:] <FIRAnalytics/INFO> Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist 
2016-11-21 21:44:28.782 GunnOracleGoogleSignIn[12677] <Debug> [Firebase/Core][I-COR000019] Clearcut post completed. 
2016-11-21 21:44:30.143 GunnOracleGoogleSignIn[12677:] <FIRAnalytics/WARNING> The AdSupport Framework is not currently linked. Some features will not function properly. Learn more at (Can't show goo.gl url) 
2016-11-21 21:44:31.086 GunnOracleGoogleSignIn[12677:] <FIRAnalytics/INFO> Firebase Analytics enabled 
2016-11-21 21:44:31.841 GunnOracleGoogleSignIn[12677:470666] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'uiDelegate must either be a |UIViewController| or implement the |signIn:presentViewController:| and |signIn:dismissViewController:| methods from |GIDSignInUIDelegate|.' 
*** First throw call stack: 
(
    0 CoreFoundation      0x00000001076ffd4b __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x000000010716121e objc_exception_throw + 48 
    2 CoreFoundation      0x00000001077692b5 +[NSException raise:format:] + 197 
    3 GunnOracleGoogleSignIn    0x000000010619df7e -[GIDSignIn signInWithOptions:] + 88 
    4 GunnOracleGoogleSignIn    0x00000001061a1c13 -[GIDSignInButton pressed] + 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 sendEvent:] + 4011 
    11 UIKit        0x000000010825454b -[UIApplication sendEvent:] + 371 
    12 UIKit        0x0000000108a3fa0f __dispatchPreprocessedEventFromEventQueue + 3248 
    13 UIKit        0x0000000108a38745 __handleEventQueue + 4879 
    14 CoreFoundation      0x00000001076a48e1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    15 CoreFoundation      0x0000000107689b0c __CFRunLoopDoSources0 + 556 
    16 CoreFoundation      0x0000000107688ff6 __CFRunLoopRun + 918 
    17 CoreFoundation      0x0000000107688a04 CFRunLoopRunSpecific + 420 
    18 GraphicsServices     0x000000010bad6a6f GSEventRunModal + 161 
    19 UIKit        0x0000000108236808 UIApplicationMain + 159 
    20 GunnOracleGoogleSignIn    0x00000001060f669f main + 111 
    21 libdyld.dylib      0x000000010a4a368d start + 1 
    22 ???         0x0000000000000001 0x0 + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

讓我知道是否有其他任何需要被包括在內。

+1

請仔細閱讀錯誤消息。關鍵信息是''uiDelegate必須是| UIViewController |或實現| signIn:presentViewController:|和| signIn:dismissViewController:|方法來自| GIDSignInUIDelegate | .'' – vadian

+0

@vadian所以你知道如何解決這個錯誤,因爲我沒有完全理解它那麼好 –

+0

因爲'AppDelegate'不是視圖控制器,所以你需要實現建議的方法。 – vadian

回答