I am trying to embed the Google+ login in an iOS application using the Swift language.
My code is as follows:
var kClientId = "My Client ID from Dev Console"
var signIn = GPPSignIn.sharedInstance()
signIn.shouldFetchGooglePlusUser = true
signIn.shouldFetchGoogleUserEmail = true
signIn.shouldFetchGoogleUserID = true
signIn.clientID = kClientId
signIn.scopes = [kGTLAuthScopePlusLogin]
signIn.delegate = self
signIn.authenticate()
For test purposes, I created lable and wanted to change this for the email of the user who is logged in.
if (GPPSignIn.sharedInstance().userID != nil) {
var user = GPPSignIn.sharedInstance().googlePlusUser
userName.text = user.name.JSONString()
if (user.emails != nil){
userEmailLable.text = user.emails.first?.JSONString() ?? "no email"
} else {
userEmailLable.text = "no email"
}
} else {
println("User ID is nil")
}
After I click the "Login" button, the Safari tab will open, and I can enter my Google email address and password, and it asks permission for certain things, and after clicking the "Accept" button, it returns to the application. My userEmailLable does not change, and "User ID is no" is output. This happens all the time and there has not been a single successful login.
Google , URL- , Google Developer , .
AppDelegate.swift
func application(application: UIApplication, openURL url: NSURL, sourcApplication: String, annotation: AnyObject?) -> Bool {
return GPPURLHandler.handleURL(url, sourceApplication: sourcApplication, annotation: annotation)
}
- , ? !