我正在努力使用登录按钮上的google文档。基本上,我想在按下Google登录按钮后立即在屏幕上添加活动指示器。但是,实际上只有两个函数可以从下面的文档中调用
- signInWillDispatch:error:
登录流程已完成选择如何继续,并且UI不应再显示微调器或其他"请等待"元件。更多...
- signIn:didSignInForUser:withError:
登录流程已完成,如果错误为零则成功。更...`
我不知道在哪里可以放置我的beginActivityIndicator代码,因为我不知道在按下Google登录按钮后会立即调用哪个函数。
谢谢,
- 更新代码 - 以下是我在loginVC中的四个函数,它们继承自GIDSignInUIDelegate和GIDSignInDelegate。几乎我需要在SignInWillDispatch之前找到函数,以便我可以启动活动指示器。但是,我找不到文档中的位置。我尝试在Google按钮上添加点击手势识别器。当我这样做时,登录功能完全停止工作,就好像它只是一个空白的UIView
// Google login buttob
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
// Uncomment to automatically sign in the user.
//GIDSignIn.sharedInstance().signInSilently()
// TODO(developer) Configure the sign-in button look/feel
let googleSignInBtn = GIDSignInButton()
googleSignInBtn.frame.size = loginButton.frame.size
googleSignInBtn.center.x = loginButton.center.x
googleSignInBtn.center.y = loginButton.center.y + 80
googleSignInBtn.style = .Wide
self.view.addSubview(googleSignInBtn)
func signIn(signIn: GIDSignIn!, presentViewController viewController: UIViewController!) {
print("Signed in with google")
}
func signInWillDispatch(signIn: GIDSignIn!, error: NSError!) {
print("Signin Will Dispatch")
}
func signIn(signIn: GIDSignIn!, dismissViewController viewController: UIViewController!) {
print("GoogleSignInDismiss")
}
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
activityIndicatorBegin() // Having the activity indicator start here is too late. I need it to start as soon as the google button is pressed. Otherwise there would be a moment just after the google view dismisses without activity indicator
if let error = error {
print(error.localizedDescription)
return
}
let authentication = user.authentication
let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken, accessToken: authentication.accessToken)
FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
if let error = error {
self.showErrorAlert("Error Sign in Firebase with google", message: error.localizedDescription)
} else {
}
self.activityIndicatorEnd()
}
}
func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!, withError error: NSError!) {
// Perform any operations when the user disconnects from app here.
print("didDisconnectWithUser")
}
答案 0 :(得分:0)
问题解决了。我无法通过像上面那样以编程方式创建按钮来解决它。我所做的是创建了一个UIButton并简单地执行以下操作
@IBAction func signInWithGoogleBtn(sender: AnyObject) {
activityIndicatorBegin()
GIDSignIn.sharedInstance().signIn()
}