爲您定製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
}
}
Google SDK中沒有任何完成處理程序的方法 –
您可以添加NotificationObserver。 – Wolverine