facebook openurl登录ios 9方法ios swift

时间:2016-07-11 06:52:36

标签: ios swift facebook ios9 openurl

我在我的应用程序中同时集成了facebook和gmail,但只要我为gmail登录添加了打开的url功能,facebook登录就会停止工作。 我在我的应用中使用此代码打开网址

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {

    var shouldOpen :Bool = FBSDKApplicationDelegate.sharedInstance().application(application,openURL: url,sourceApplication: sourceApplication,annotation: annotation)

    shouldOpen = shouldOpen ? shouldOpen : GIDSignIn.sharedInstance().handleURL(url,
                                                                                sourceApplication: sourceApplication,
                                                                                annotation: annotation)

    return shouldOpen

}

这适用于facebook登录,但是当我为ios 9添加openmail的gmail方法时,问题就出现了,即在登录facebook之后我们不会重定向回应用程序。在模拟器中,白色屏幕显示在safari中。 ios 9的gmail登录代码

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    if #available(iOS 9.0, *) {

        return GIDSignIn.sharedInstance().handleURL(url,
                                                    sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String?,
                                                    annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
    }
    return true
}

如果我注释掉上面的代码,facebook登录正常工作我想问题是我必须在ios 9中为facebook的openurl返回布尔值。但我不知道该怎么办? TIA

3 个答案:

答案 0 :(得分:3)

找到我的答案我需要实现openurl的两种方法,比如这个

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {

    var shouldOpen :Bool = FBSDKApplicationDelegate.sharedInstance().application(application,openURL: url,sourceApplication: sourceApplication,annotation: annotation)

    shouldOpen = shouldOpen ? shouldOpen : GIDSignIn.sharedInstance().handleURL(url,
                                                                                sourceApplication: sourceApplication,
                                                                                annotation: annotation)
    return shouldOpen

}

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    if #available(iOS 9.0, *) {
        var shouldOpen :Bool = FBSDKApplicationDelegate.sharedInstance().application(
            app,
            openURL: url,
            sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String,
            annotation: nil)

        shouldOpen = shouldOpen ? shouldOpen : GIDSignIn.sharedInstance().handleURL(url,sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String?,
                                                                                    annotation: options[UIApplicationOpenURLOptionsAnnotationKey])

        return shouldOpen
    }
    return true
}

我只需要检查ios 9的facebook open url方法

编辑swift 3.0功能已更改

private func application(application: UIApplication, openURL url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool {


    return  FBSDKApplicationDelegate.sharedInstance().application(application,open: url as URL!,sourceApplication: sourceApplication,annotation: annotation)

}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    if #available(iOS 9.0 , *){
     return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: "UIApplicationOpenURLOptionsKey", annotation: nil)   

    }

return true
}

答案 1 :(得分:1)

我试过@Aruk k回答但是没有为我工作

我过去1个月也遇到过这个问题。关注所有步骤和教程,但没有任何效果。我正在ios 10 swift 3中将facebook登录与firebase集成。最后,我能够成功实现它。我通过在AppDelegate文件中进行了以下更改来纠正它。

public interface IOrganizationService {
    Entity Retrieve(string entityName, Guid id, ColumnSet columnSet);
}

我希望它可以帮助别人

在运行10.2

的ios 10.2仿真器,iPhone 6 Plus上进行了测试

答案 2 :(得分:0)

Swift 4. Xcode 9. iOS 11. Google SignIn + Facebook SignIn。 AppDelegate中。

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {

    var signedIn: Bool = GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation)

    signedIn = signedIn ? signedIn : FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)

    return signedIn
}

@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {

    var signedIn: Bool = GIDSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])

    signedIn = signedIn ? signedIn : FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: nil)

    return signedIn
}