I am developing an iOS app that needs to open a Facebook user or page profile on the Facebook App (if installed) from my app. I have the public profile URL of the user or page, such as https://www.facebook.com/nirav.parmar.7169709. How can I use a custom URL scheme to launch the Facebook App and show the profile? If the Facebook App is not installed, I want to open the profile in Safari instead.
I already tried this way but it's not work for me:
fb://profile/nirav.parmar.7169709 (Not work)
fb://profile?username=nirav.parmar.7169709 (Not Work)
fb://profile/100004929307564 (worked - but how to find user_id from this url "https://www.facebook.com/nirav.parmar.7169709")
You can use canOpenURL
to check if app can be opened.
let appURL = URL(string: "fb://profile/100004929307564")!
let browserURL = URL(string: "https://www.facebook.com/nirav.parmar.7169709")!
if UIApplication.shared.canOpenURL(appURL) {
UIApplication.shared.open(appURL)
} else {
UIApplication.shared.open(browserURL)
}