Finally, the problem is sorted using the latest Google+ Sign SDK, and the app is also approved by Apple. I am posting a solution for iOS 9 and iOS 8 .
For integration use CocoaPods .
pod 'Google/SignIn'
To start by logging in, you need to follow the same steps as in the Start Integration section here
Now in the Add Login section, I want a custom button to be configured in my custom UIViewController class to initiate the login process. In the Google Developer link, they are redirected only to AppDelegate. Therefore, to avoid this, I will not use GIDSignInDelegate in the AppDelegate class
I will only make changes to the following two AppDelegate methods
//This is available for iOS 9 and above. So we have to use this method if we are integrating Google Sign In in iOS 9 func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) //This is available prior iOS 9 and is available for iOS 8,7 etc. This is a deprecated method for iOS 9. You have to override this too if your app supports iOS 8 platform. func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
Thus, the definitions will be as follows:
func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { if #available(iOS 9.0, *) { return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey] as? String) } else { // Fallback on earlier versions } return true } func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return GIDSignIn.sharedInstance().handleURL(url,sourceApplication: sourceApplication,annotation: annotation) }
Now let's move on to our custom class UIViewController ie LoginViewController , implement GIDSignInDelegate and GIDSignInUIDelegate
class LoginViewController: UIViewController, GIDSignInDelegate, GIDSignInUIDelegate { }
There is a UIButton user login for Google +, the definition of which
@IBAction func googleLoginButtonPressed(sender: AnyObject) {
Now implement delegate methods for Google + Login
func signIn(signIn: GIDSignIn!, dismissViewController viewController: UIViewController!) { self.dismissViewControllerAnimated(true) { () -> Void in } } func signIn(signIn: GIDSignIn!, presentViewController viewController: UIViewController!) { self.presentViewController(viewController, animated: true) { () -> Void in } } 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 if user gets disconnected }
Now it will work in both iOS 8 and 9, without moving your application outside of Safari to sign in to Google+.