Search code examples
iosswift3subscript

Google sign in ambiguous reference to member 'subscript'


application:openURL:options: method of app delegate. The method should call the handleURL method of the GIDSignIn instance, which will properly handle the URL that your application receives at the end of the authentication process.

Directly copied from firebase guide docs but still has errors.

func application(application: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool {
    return GIDSignIn.sharedInstance().handleURL(url as URL!, sourceApplication: 
        options[UIApplicationOpenURLOptionsSourceApplicationKey]  //Error is here
        //Ambiguous reference to member 'subscript' error is shown.

        as? String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}

Solution

  • You have a few issues. The delegate method should have the following signature in Swift 3:

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
    

    and the whole method would be:

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
    }