7

Can someone tell the URL schemes to open the Facebook application from my app?

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
kazui
  • 141
  • 1
  • 1
  • 6
  • http://stackoverflow.com/questions/10416338/open-a-facebook-link-by-native-facebook-app-on-ios some time this ink will help you. – uma Sep 06 '15 at 12:55

1 Answers1

19

Use fb://.

canOpenURL returns a BOOL value indicating whether or not the URL’s scheme can be handled by some app installed on the device. If canOpenURL returns YES then the application is present on the device. If the user has Facebook installed on their device we open it. If the user does not have Facebook installed we open the page through a link, which will launch Safari.

// Check if FB app installed on device
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/355356557838717"]];
}
else {
   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.facebook.com/DanielStormApps"]];
}

Check out iPhone URL Schemes for a list of what else you can achieve via URL Schemes.

Also, starting at iOS 9 you must include LSApplicationQueriesSchemes in your info.plist.

enter image description here

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
  • sorry daniel but how can you know 355356557838717 this part of your url, because if i open the fb application and i go to my profile i don't find any url, where i've to look? – kazui Sep 06 '15 at 13:55
  • @kazui If its a Facebook page ID you're after make sure you're logged in as your page and navigate to the About section. The page ID should be located at the bottom. Alternatively, you can use a website like [Find My Facebook ID](https://lookup-id.com/) and find it via the pages URL. – Daniel Storm Sep 06 '15 at 14:00
  • for some reason, when I call fb://profile/ it opens the facebook app in the right page, then immediately crashes... Does this happen to anyone else? – gool Mar 15 '17 at 15:24