How to open a facebook\instagram page \ profile from your app? (swift)

532 Views Asked by At

I'm trying to open a facebook page from my app. Here is the code:

let facebookWebURL = URL.init(string: "https://www.facebook.com/aviramnet")
let facebookAppURL = URL.init(string: "fb://profile/220780122049926")

if (UIApplication.shared.canOpenURL(facebookAppURL!)){
    UIApplication.shared.open(facebookAppURL!, options: [:], completionHandler: nil)
}else{
    UIApplication.shared.open(facebookWebURL!, options: [:], completionHandler: nil)
}

But it only opens the app on Safari browser. Did I miss something?

And yes, I have the Facebook app installed.

1

There are 1 best solutions below

0
Aviram Netanel On

you need to add in the app's info.plist :

under the LSApplicationQueriesSchemes array add an item:

fb for facebook, and instagram for instagram :

enter image description here