Ios 谷歌didSignInForUser没有';不要在swift 3中开火
我正在我的项目中进行谷歌登录。我使用CocoaPods安装了SDK。我以前也用Objective-C编写过这个应用程序。因此,我从我的旧项目中拖出了相同的Google配置文件(GoogleService Info.plist) 我跟着。但当我按下“登录”按钮时,我指向谷歌网页,输入用户名密码后,它会返回到我的应用程序。但是这个委托不会触发Ios 谷歌didSignInForUser没有';不要在swift 3中开火,ios,swift,swift3,google-signin,Ios,Swift,Swift3,Google Signin,我正在我的项目中进行谷歌登录。我使用CocoaPods安装了SDK。我以前也用Objective-C编写过这个应用程序。因此,我从我的旧项目中拖出了相同的Google配置文件(GoogleService Info.plist) 我跟着。但当我按下“登录”按钮时,我指向谷歌网页,输入用户名密码后,它会返回到我的应用程序。但是这个委托不会触发 func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withErro
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
let dm = Datamanager.sharedInstance
dm.gplusEmail = email
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RETURNED_GOOGLE"), object: nil)
// ...
} else {
print("\(error.localizedDescription)")
}
}
我的登录按钮是一个ui按钮
,在我的ViewController中,我以这种方式实现了:
@IBAction func googleClick(_ sender: UIButton) {
strLoggedWay="google"
GIDSignIn.sharedInstance().signIn()
}
请帮帮我。我的代码处理有什么问题
//In your login view controller
@IBAction func googleClick(_ sender: UIButton) {
strLoggedWay="google"
GIDSignIn.sharedInstance().clientID = //getGoogleClientId
GIDSignIn.sharedInstance().serverClientID = //getGoogleServerClientId
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().scopes = @["https://www.googleapis.com/auth/userinfo.profile","https://www.googleapis.com/auth/userinfo.email"]
GIDSignIn.sharedInstance().signIn()
}
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
let dm=Datamanager.sharedInstance
dm.gplusEmail=email
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RETURNED_GOOGLE"), object: nil)
// ...
} else {
print("\(error.localizedDescription)")
}
}