OGeek|极客世界-中国程序员成长平台

标题: ios - 处理 openURL : with Facebook and Google [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:10
标题: ios - 处理 openURL : with Facebook and Google

我的应用程序中的用户可以使用 2 个服务登录:Facebook 或 Google

一切正常,但是,在:

- (BOOL)applicationUIApplication *)application openURLNSURL *)url sourceApplicationNSString *)sourceApplication annotation: (id)annotation {
    ...
}

我应该决定调用 Facebook 回调还是 Google 回调

如果用户有应用程序,这很容易,比我由 sourceApplication 决定 但如果不是(没有链接 native Facebook 帐户、没有 FB 应用程序、没有 GooglePlus 应用程序),它会链接到浏览器 我不知道它是来自 Facebook 还是来自 Google

有没有办法决定调用什么?喜欢

- (BOOL)applicationUIApplication *)application openURLNSURL *)url sourceApplicationNSString *)sourceApplication annotation: (id)annotation {

    // how to decide?
    if (facebook) {

        return [FBSession.activeSession handleOpenURL:url];

    } else if (google) {

        return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];

    }

}



Best Answer-推荐答案


我们不需要显式检查 URL,下面的代码可以做到:

- (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation
{

    if ([GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]) {
        return YES;
    }else if([FBAppCall handleOpenURL:url sourceApplication:sourceApplication]){
        return YES;
    }

    return NO;
}

关于ios - 处理 openURL : with Facebook and Google,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50364597/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4