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