[英]IOS- Google sign in button
在我的應用中,我有我的Google登錄按鈕,該按鈕很好用,但單擊此按鈕時出現問題。 僅當我單擊按鈕約3秒鍾時,指示燈才會亮起。 我將點擊按鈕,然后直接轉到權限頁面或其他活動。 預先感謝您的幫助。
AppDelegate:
import GoogleSignIn
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
FIRApp.configure()
GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
return true
}
func application(application: UIApplication,
openURL url: NSURL, options: [String: AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
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
// ...
} else {
print("\(error.localizedDescription)")
}
}
func signIn(signIn: GIDSignIn!, didDisconnectWithUser user: GIDGoogleUser!,
withError error: NSError!) {
// Perform any operations when the user disconnects from app here.
// ...
}
}
登錄:
import GoogleSignIn
class Login: UIViewController,GIDSignInUIDelegate, GIDSignInDelegate {
@IBOutlet weak var google_view: UIView!
let login_button_google = GIDSignInButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
override func viewDidLoad() {
super.viewDidLoad()
hideKeyboard()
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.login")
GIDSignIn.sharedInstance().scopes.append("https://www.googleapis.com/auth/plus.me")
login_button_google.center = self.google_view.center
self.view!.addSubview(login_button_google)
}
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
// Perform any operations on signed in user here.
userId = user.userID // For client-side use only!
idToken = user.authentication.idToken // Safe to send to the server
fullName = user.profile.name
email = user.profile.email
performSegueWithIdentifier("loginToDoing", sender: nil)
} else {
print("\(error.localizedDescription)")
}
}
}
我已經解決了我的問題,這要歸功於:
如果有人對Google登錄按鈕有疑問,則可能是某些委托元素。 在我的情況下,問題是在viewDidLoad方法中帶有hideKeyboard()的uiviewcontroller擴展。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.