Jigar Tarsariya Jigar Tarsariya - 1 month ago 16
iOS Question

OpenURL for Facebook and Twitter in app delegate?

I am using Facebook SDK and Twitter SDK for login and signup.

But they both are not opening url from one common method. Like i have written like below code for Facebook,

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
{
if(url.scheme == "fb1651015905222312")
{
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
return true
}


This works fine and for twitter i have to comment this above method and have to write it like,

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
if Twitter.sharedInstance().application(app, openURL:url, options: options) {
return true
}
return true
}


This works fine for twitter only.

Issue is that i need to write one common method to open their URL in appDelegate. So how do i overcome it?

Thanks in advance.

NOTE : We can't write both method in app delegate.

Answer

Finally i found solution for this question.

Here is the method which allows me to write url for Facebook and Twitter both.

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {

    if Twitter.sharedInstance().application(app, openURL:url, options: options) {
        return true
    }

    let sourceApplication: String? = options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String
    return FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: sourceApplication, annotation: nil)
}

Thanks to all who had tried to answer my question.

Thanks.

Comments