Google + login Disconnect iOS application from AppStore using google sdk v3.x

After digging multiple times, I post my problem here. I use the google sign in the latest sdk in my application, and the application supports iOS 8+. I am currently using Xcode 7.2. Recently, my application was rejected with a common reason that many users have experienced in the past:

FROM APPSTORE
We noticed that the user goes to Safari to log in or register for an account, which provides a bad user interface. In particular, logging into Google to log in to Safari to log in.

Next steps

10.6 Please go to your application so that users can log in or register an account in the application.

We recommend that you implement the Safari API to display web content in your application. Safari Browser allows you to display the URL and verify the certificate from the in-app browser in the application so that customers can verify the URL of the web page and SSL certificate to confirm that they enter their credentials on a legitimate page.
End

I already know this rejection, as the apple rejected a lot of applications that exit the login in the Safari browser. Here are some links for reference.
https://code.google.com/p/google-plus-platform/issues/detail?id=900
https://github.com/Torsten2217/google-plus-platform/issues/900

and some more links that you can easily find on the Internet

In May 2015, Google released a new sdk with its own web view. The complete integration process is available here http://www.appcoda.com/google-sign-in-how-to/ .
It worked great with iOS 8 and also represented the controller.

Now I used the latest google svd that I installed through CocoaPods https://developers.google.com/identity/sign-in/ios/start
In the above link from Google there is an example of Try Sign-In for iOS , which I tried. Now it opens its own SFSafariViewController only in iOS 9, but in iOS 8 the input stream again goes beyond the application into the Safari browser.

In the comments, apple reviewer asked for a SafariViewController , but the accessibility of the control is from iOS 9 and above . Here is the link https://developer.apple.com/library/ios/documentation/SafariServices/Reference/SFSafariViewController_Ref/
How can I achieve this with the latest google sdk in iOS 8.
The reviewer does not mention the version of iOS that he tested.

Now can someone help me sort this out. How can I control in iOS 8, the built-in controller for logging in to Google.

+5
source share
1 answer

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) { // Initialize sign-in var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) //assert(configureError == nil, "Error configuring Google services: \(configureError)") if configureError != nil { //Handle your error }else { GIDSignIn.sharedInstance().shouldFetchBasicProfile = true GIDSignIn.sharedInstance().clientID = kClientId GIDSignIn.sharedInstance().delegate = self GIDSignIn.sharedInstance().uiDelegate = self //This did the trick for iOS 8 and the controller is presented now in iOS 8 //We have to make allowsSignInWithBrowser false also. If we dont write this line and only write the 2nd line, then iOS 8 will not present a webview and again will take your flow outside the app in safari. So we have to write both the lines, Line 1 and Line 2 GIDSignIn.sharedInstance().allowsSignInWithBrowser = false //Line 1 GIDSignIn.sharedInstance().allowsSignInWithWebView = true //Line 2 GIDSignIn.sharedInstance().signIn() } } 

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+.

+10
source

Source: https://habr.com/ru/post/1247147/


All Articles