1

I am learning writing ios app with Swift.

But when I follow the instruction on the Google Developers page.

https://developers.google.com/identity/sign-in/ios/start?ver=swift

Xcode show many compile wrong for me.

For example, this code on the instruction need to add in AppDelegate:

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)
}

This will show

ambiguous reference to member 'subscript'

And I need to change this code to:

private func application(application: UIApplication,
                     openURL url: URL, options: [String: AnyObject]) -> Bool {
        return GIDSignIn.sharedInstance().handle(url as URL!,
                                                    sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication.rawValue] as? String,
                                                    annotation: options[UIApplicationOpenURLOptionsKey.annotation.rawValue])
    }

Then it will pass the compiler.

Another compile error is that two code need to add in AppDelegate:

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    
      // ...
    } else {
      print("\(error.localizedDescription)")
    }
}
func signIn(signIn: GIDSignIn!, didDisconnectWithUser user:GIDGoogleUser!,
  withError error: NSError!) {
    // Perform any operations when the user disconnects from app here.
    // ...
}

Debugger tell me that I need to replace function name

"signIn" to be "sign"

And it will pass the compiler.

The last two compile error is same as upside.

Compiler tell me that I need to change the function "signIn" as "sign" in my UIviewcontroller code.

"BUT"

Although I fully follow the compiler instructs, and successful run simulator, I still can't get the data when user allow app get the user's data.

And compiler show this for me:

Implementation of application:openURL:sourceApplication:annotation: not found. Please add the handler into your App Delegate. Class: MyClassName.AppDelegate

SO......

Do any one know why application can't find my handler?

I guess those compile errors are cause of ios updated to 10, then I don't know whether or not the action that change function's name that let me couldn't get the google's data.

Thanks for your answer. :)

Google Developers page: https://developers.google.com/identity/sign-in/ios/sign-in?ver=swift

  • Try [Integrating Google Sign-In into your iOS app](https://developers.google.com/identity/sign-in/ios/sign-in), this document shows how to enable sign-in, where to put the configuration. The document also provide the [dependencies and configure your Xcode project](https://developers.google.com/identity/sign-in/ios/start-integrating). – Mr.Rebot Oct 20 '16 at 06:50
  • Here are a very informative tutorials - [Swift: How to integrate Google Login/Sign-In SDK with Cocoapods](https://www.youtube.com/watch?v=tYtBX6efJkc), [Sign in series #1: The New Google Sign-in for iOS (Route 85)](https://www.youtube.com/watch?v=-26DGO_E1ds), and [Sign in series #2: Adding Google Sign-in to your iOS App (Route 85)](https://www.youtube.com/watch?v=QmnI5c85sf0). Hope this helps. – Mr.Rebot Oct 20 '16 at 06:50
  • Hey thanks you for your answer. :) Those tutorials r not effective to me. I got the solution at http://stackoverflow.com/questions/40136785/trouble-handling-google-sign-in-swift-3. Very awesome. And still thank you again. :D – seeyoulater Oct 22 '16 at 07:15

0 Answers0