I\'m using Google Sign-In for iOS and when using simulator it\'s working fine because no google app is installed and user is fetch, but when using my iPhone 6 device open yo
import UIKit
import GoogleSignIn
import Google
class ViewController: UIViewController,GIDSignInUIDelegate, GIDSignInDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let gidSingIn = GIDSignIn()
GIDSignIn.sharedInstance().uiDelegate = self
gidSingIn.delegate = self
GIDSignIn.sharedInstance().delegate = self
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
let button = GIDSignInButton(frame:CGRectMake(0,0,30, 200))
button.center = self.view.center
button.backgroundColor = UIColor.blueColor()
self.view.addSubview(button)
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func signInGoogle(sender: AnyObject) {
print("pressed")
}
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
// Perform any operations on signed in user here.
print(user.userID) // For client-side use only!
print(user.authentication.idToken) // Safe to send to the server
print(user.profile.name)
print(user.profile.givenName)
print(user.profile.familyName)
print(user.profile.email)
print(user.authentication.accessToken)
print(user.profile)
} else {
print("\(error.localizedDescription)")
}
}
func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!,
withError error: NSError!) {
}
} // this is login with gmail account not for googleplus. just copy and past within your controller. and add following func in your AppDelegate Class
func application(application: UIApplication,
openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
var options: [String: AnyObject] = [UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication!,UIApplicationOpenURLOptionsAnnotationKey: annotation]
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: sourceApplication,
annotation: annotation)
}