2016-12-29 80 views
1

在iOS Google SDK中,我無法在signIn處理成功時找到處理事件的相關方法。Google SDK iOS - sign()方法完成處理程序

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { } 

這種方法並不需要完成處理的參數,是否有可以處理簽到過程完成任何其他API方法?

我在文檔中找不到任何東西,Google的官方教程也很不方便。

爲什麼我需要這個? 我創建了單獨的GoogleManager類來處理谷歌登錄過程,並且我想從我的VC傳遞一個完成處理程序,在完成時執行segue。應該如何處理它?

+0

Google SDK中沒有任何完成處理程序的方法 –

+0

您可以添加NotificationObserver。 – Wolverine

回答

2

爲您定製GoogleManager創建一個代表,並創建GoogleManager內該委託的實例和實施類代表在其中創建自定義類GoogleManager的情況下,之後,當GIDSignInDelegate方法稱爲使用您的自定義委託,並呼籲其方法。所以它應該看起來像這樣。

protocol GoogleManagerDelegate { 
    func receiveResponse(user: GIDGoogleUser)// Pass Parameter that you want 
} 

現在,當你在GIDSignInDelegate方法響應GoogleManager類,你需要調用GoogleManagerDelegate方法。

class GoogleManager { 
    var delegate: GoogleManagerDelegate? 

    //Your other method  

    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { 
     self.delegate?.receiveResponse(user: user) 
    } 
} 

現在實現你的控制器其中GoogleManager您創建實例,並設置其委託實例自內GoogleManagerDelegate

class ViewController: UIViewController, GoogleManagerDelegate { 

    //Your other methods  

    func googleSignIn() { 
     let googleManager = GoogleManager() 
     googleManager.delegate = self 
    } 

    //GoogleManagerDelegate method 
    func receiveResponse(user: GIDGoogleUser) { 
     //Access user object here 
    } 
} 
+0

看到我上面的編輯 – DCDC

+0

@DCDC爲什麼你創建了sharedGIDSignIn?和它是什麼,我沒有在我的答案中提到任何事情。 –

+0

沒關係,是的工作,謝謝 – DCDC

相關問題