GIDSignIn iOS 9

2019-03-29 13:37发布

Using Googles SignIn in my AppDelegate I have

func application(application: UIApplication,
  openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
    return GIDSignIn.sharedInstance().handleURL(url,
        sourceApplication: sourceApplication,
        annotation: annotation)
}

But that function is deprecated as of iOS 9 for

application:openURL:options: 

How to return

GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation)

Using the new function for iOS 9?

2条回答
孤傲高冷的网名
2楼-- · 2019-03-29 14:10

Use this:

//Google Login
@available(iOS 9.0, *)
func application(application: UIApplication,
    openURL url: NSURL, options: [String: AnyObject]) -> Bool {
        return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}

//for IOS 8    
@available(iOS, introduced=8.0, deprecated=9.0)
func application(application: UIApplication,
    openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {

    return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication!, annotation: annotation)
}
查看更多
霸刀☆藐视天下
3楼-- · 2019-03-29 14:12

Just for reference, if using Objective-C, the method implementation is:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [[GIDSignIn sharedInstance] handleURL:url
                               sourceApplication:sourceApplication
                                      annotation:annotation];
}

If on iOS 9, it would be recommended to also implement the new format:

- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options {
    return [[GIDSignIn sharedInstance] handleURL:url
                               sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
                                      annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
查看更多
登录 后发表回答