I'm trying to implement a google sign in button, when I add the following lines to my AppDelegate.swift file, I get this error:
Cannot subscript a value of type '[String : AnyObject]' with an index of type 'String'
Any ideas what's wrong with this code? By the way, this code is just copied and pasted from google page at: https://developers.google.com/identity/sign-in/ios/sign-in?configured&ver=swift
func application(application: UIApplication,
openURL url: NSURL, options options: [String: AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey],
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
Thanks
Update your device to the latest version of iOS or iPadOS. You can update your device wirelessly by going to Settings > General > Software Update and if there is an update, follow the onscreen instructions to update your device. Clear the history, cache and cookies to see if this fixes your problem.
Your sign-in may be blocked if the device or location you're using is new. Try again from a device or location that you commonly sign in from. Sign in to your Google Account on the new device and try again the following week.
How can you fix Google sign-in error on android phone? Some of the solutions to this error include disabling the 2-step verification process, removing and adding your Google account, and restoring your device to its factory settings.
On your iPhone or iPad, open the Safari app. Go to www.google.com. Tap your profile image or Sign in. Follow the sign-in steps.
handleURL is looking for arguments of type "String" for sourceApplication and annotation, but options is providing "AnyObject." Casting those dictionary values to "String" oughtta do it.
Try this:
Update: Swift 3
func application(_ application: UIApplication,
open url: URL, options: [UIApplicationOpenURLOptionsKey: Any]) -> Bool
return GIDSignIn.sharedInstance().handle(url,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation] as? String)
}
Swift 2
func application(application: UIApplication,
openURL url: NSURL, options: [String: AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
annotation: options[UIApplicationOpenURLOptionsAnnotationKey] as? String)
}
This took me forever, too. Hope that helps!
Xcode 8 Swift 3
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(
url,
sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With