kazui
kazui

Reputation: 141

Open Facebook application from my app

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

Upvotes: 7

Views: 10313

Answers (1)

Daniel Storm
Daniel Storm

Reputation: 18908

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

Upvotes: 19

Related Questions