gpt4 book ai didi

ios - Google didSignInForUser 不会在 swift 3 中触发

转载 作者:行者123 更新时间:2023-11-28 08:05:51 27 4
gpt4 key购买 nike

我正在我的项目中进行 Google 登录。我使用 CocoaPods 安装了 SDK。我以前用 Objective-C 编写过同样的应用程序。因此,我从我的旧项目中拖出相同的 Google 配置文件 (GoogleService-Info.plist)。

然后我关注了this with CocoaPods installed method .但是,当我按下登录按钮时,我将定向到 Google 网页,在我输入用户名密码后,它会返回到我的应用程序。但是这个委托(delegate)不会触发。

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)")
}
}

我的登录按钮是一个 UIButton,在我的 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)")
}
}

关于ios - Google didSignInForUser 不会在 swift 3 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45125286/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com