2017-02-14 12 views
0

私は私の最初のビューで私のログインボタンをクリックすると私はGoogleのsignIn APIを使用して私はアクセスしてsegueのためのperformeを使用した後、自分自身を記録し、私のデータを取得することができます2番目のビュー。 2番目のビューでログアウトしようとすると、私の文字列「deco」が表示され、最初のページに戻ります。しかし、私は再び自分自身を記録しようとすると、彼はこのエラーでクラッシュ:AppDelegate送信応答swift3

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|.'

私はログアウト機能が動作しませんでしたと思うし、また、私はappDelegateでセグエの利用performeが最高Methodeのだとは思いませんあなたは何か他のものでそれを作っていますか?私は同じことを持っている私の2番目のビューで

マイfirstViewController

class ViewController: UIViewController, GIDSignInUIDelegate{ 

override func viewDidLoad() { 
    super.viewDidLoad() 
    GIDSignIn.sharedInstance().uiDelegate = self 
    // Do any additional setup after loading the view, typically from a nib. 
} 

@IBAction func btn(_ sender: Any) { 
    GIDSignIn.sharedInstance().signIn() 
}} 

(届出を期待)、唯一の変更は)GIDSignIn.sharedInstance(である。切断()

マイappDelegate

class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate { 

var window: UIWindow? 


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    // Override point for customization after application launch. 
    var configureError : NSError? 
    GGLContext.sharedInstance().configureWithError(&configureError) 
    if (configureError != nil) 
    { 
      print("We have an error ! \(configureError)") 
    } 
    else 
    { 
     print("Google ready sir !") 

    } 
    GIDSignIn.sharedInstance().delegate = self 

    return true 
} 

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]) 
} 
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) 
{ 
    if (error == nil) { 
     // Perform any operations on signed in user here. 
     let userId = user.userID     // For client-side use only! 
     let idToken = user.authentication.accessToken // 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 
     print("userId =>\(userId)") 
     print("idToken =>\(idToken)") 
     print("fullName =>\(fullName)") 
     print(" familyName=>\(familyName)") 
     print(" givenName=>\(givenName)") 
     print("email =>\(email)") 
     print("info => \(user.authentication)") 
     guard let rvc = self.window?.rootViewController as? ViewController 
      else { 
       return 
     } 
     rvc.performSegue(withIdentifier: "test", sender: nil) 



    } else { 
     print("\(error.localizedDescription)") 
    } 
} 



func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) 
{ 
    print("Deco") 
} 
// Other func not usefull 
が含まれています

}

答えて

0

あなたはあなたのViewControllerAppDelegateGIDSignInUIDelegateを実装していますが、実装はAppDelegateに限られます。

実装をどちらにするかを決定し、そこでサポートされているプロトコルのみを宣言する必要があります。

GIDSignIn.sharedInstance().uiDelegate = self 

が、それは必要なメソッドを持っていない:ViewControllerは実際の代理人であるので、私の推測では、あなたがクラッシュしているということです。 Google docs hereを見ると、AppDelegateに実装することをお勧めします。これにはいくつかのステップが含まれています。最初の手順は、代わりにAppDelegateインスタンスにuiDelegateを設定することです。ような何か:。

GIDSignIn.sharedInstance().uiDelegate = UIApplication.shared.delegate as? GIDSignInUIDelegate 

が次に実装を追加:私はGIDSignIn.sharedInstanceを(書いていない場合は、私のビューコントローラでuiDelegate =自己)

func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, 
    withError error: NSError!) { 
    if (error == nil) { 
     // 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 
     // ... 
    } else { 
     print("\(error.localizedDescription)") 
    } 
} 

func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, 
    withError error: NSError!) { 
    // Perform any operations when the user disconnects from app here. 
    // ... 
} 
+0

を、私は、同じメッセージでクラッシュを得ました一度でもログすることはできません –

関連する問題