I have a link to my facebook, on my website, which opens in the phone's browser.
I would like it to open in the facebook app by default, if the app is installed.
I tried to put this code but it does not work. Opens the facebook page always and only via safari and not through the facebook app. If you can help me please.
@IBAction func supporto(_ sender: UIBarButtonItem) {
let Username = "831831923611308"
let appURL = NSURL(string: "fb://profile/\(Username)")!
let webURL = NSURL(string: "https://facebook.com/\(Username)")!
let application = UIApplication.shared
if application.canOpenURL(appURL as URL) {
if #available(iOS 10.0, *) {
application.open(appURL as URL)
} else {
// Fallback on earlier versions
}
} else {
if #available(iOS 10.0, *) {
application.open(webURL as URL)
} else {
// Fallback on earlier versions
}
}
}
I can confirm that the code you are using does work. I placed it in a new project, installed it on my phone, and set the
Info.plist
values as follows:My code is as follows:
There are a few reasons that your code may not have worked.
Info.plist
load.LSApplicationQueriesSchemes
toInfo.plist
and that that is the plist that the application is set up to load.You can check that your
Info.plist
is correctly loading the Queries Schemes by going to the Project Editor's Info tab and looking to make sure thatLSApplicationQueriesSchemes
is there with the options specified:So you have to put
fb
inLSApplicationQueriesSchemes
in your info.plist