I want to redirect user to my App\'s Facebook page, so I have the following code:
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString: @\"ht
For iOS 9, You must whitelist the url's that your app will call out to using the LSApplicationQueriesSchemes key in your Info.plist.
Check here.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fb</string>
<string>fbapi</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fb-messenger-api</string>
<string>twitter</string>
<string>whatsapp</string>
<string>wechat</string>
<string>line</string>
<string>instagram</string>
<string>kakaotalk</string>
<string>mqq</string>
<string>vk</string>
<string>comgooglemaps</string>
</array>
// Swift 5, you can use this function to open fb page/profile
func openFacebookPage() {
let facebookURL = NSURL(string: "fb://profile/PageId")!
if UIApplication.shared.canOpenURL(facebookURL as URL) {
UIApplication.shared.open(facebookURL as URL)
} else {
UIApplication.shared.open(NSURL(string:
"https://www.facebook.com/PageName")! as URL)
}
}
//By Using PageId or name only
func openFacebookPage(pageID:String) {
let facebookURL = NSURL(string: "fb://profile/\(pageID)")!
if UIApplication.shared.canOpenURL(facebookURL as URL) {
UIApplication.shared.open(facebookURL as URL)
} else {
UIApplication.shared.open(NSURL(string: "https://www.facebook.com/\
(pageID)")! as URL)
}
}
//By Using Url only
func openFacebookPageURL(url:String) {
let facebookURL = NSURL(string: url)!
if UIApplication.shared.canOpenURL(facebookURL as URL) {
UIApplication.shared.open(facebookURL as URL)
} else {
UIApplication.shared.open(NSURL(string: url)! as URL)
}
}