Open Link to Facebook Page from iOS App

Open link to Facebook page from iOS app

You have to use the facebook ID for the given page rather than the vanity URL. To get the pages ID, enter your page's vanity name at the following URL and copy the value for "id":

https://graph.facebook.com/yourappspage

Once you have the id, you can set up the method to check if FB is installed using the canOpenURL method and serve the appropriate content for both states:

NSURL *facebookURL = [NSURL URLWithString:@"fb://profile/113810631976867"];
if ([[UIApplication sharedApplication] canOpenURL:facebookURL]) {
[[UIApplication sharedApplication] openURL:facebookURL];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://facebook.com"]];
}

Open facebook iOS app on a specific page

Try with the page id:

fb://profile/137947732957611

Correct way in 2018 to open Facebook app via website link?

I figured it out, hope it helps someone else.

If the device is Android, use:

fb://facewebmodal/

And if it's iOS, use:

fb://page/PAGEID

If you do it automatically you need to detect the device first and then redirect to the appropriate link.

Open Facebook application from my app

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.

Sample Image

Open a facebook link by native Facebook app on iOS

Here are some schemes the Facebook app uses, there are a ton more on the source link:

Example

NSURL *url = [NSURL URLWithString:@"fb://profile/<id>"];
[[UIApplication sharedApplication] openURL:url];

Schemes

fb://profile – Open Facebook app to the user’s profile

fb://friends – Open Facebook app to the friends list

fb://notifications – Open Facebook app to the notifications list (NOTE: there appears to be a bug with this URL. The Notifications page opens. However, it’s not possible to navigate to anywhere else in the Facebook app)

fb://feed – Open Facebook app to the News Feed

fb://events – Open Facebook app to the Events page

fb://requests – Open Facebook app to the Requests list

fb://notes – Open Facebook app to the Notes page

fb://albums – Open Facebook app to Photo Albums list

If before opening this url you want to check wether the user fas the facebook app you can do the following (as explained in another answer below):

if ([[UIApplication sharedApplication] canOpenURL:nsurl]){
[[UIApplication sharedApplication] openURL:nsurl];
}
else {
//Open the url as usual
}

Source

http://wiki.akosma.com/IPhone_URL_Schemes#Facebook

How to Open Facebook page links in website in the Facebook App

Here is the solution to create a fallback link if the app is not installed.

reference link from google
Google Deep Links with Intents

Also here is my complete final version of code
Gist of complete JS code to handle facebook links

Xcode swift link to facebook page

The problem is with the format of your Facebook url so notice the format. I use this extension to open urls. You provide it with an array of urls in the order you want them to try to be opened and it tries the first one first and if it fails it goes to the second one and so on:

extension UIApplication {
class func tryURL(urls: [String]) {
let application = UIApplication.sharedApplication()
for url in urls {
if application.canOpenURL(NSURL(string: url)!) {
application.openURL(NSURL(string: url)!)
return
}
}
}
}

And for use:

UIApplication.tryURL([
"fb://profile/116374146706", // App
"http://www.facebook.com/116374146706" // Website if app fails
])

[Update] for Swift 4:

extension UIApplication {
class func tryURL(urls: [String]) {
let application = UIApplication.shared
for url in urls {
if application.canOpenURL(URL(string: url)!) {
application.openURL(URL(string: url)!)
return
}
}
}
}

And then:

UIApplication.tryURL(urls: [
"fb://profile/116374146706", // App
"http://www.facebook.com/116374146706" // Website if app fails
])

[Update] for iOS 10 / Swift 5

extension UIApplication {
class func tryURL(urls: [String]) {
let application = UIApplication.shared
for url in urls {
if application.canOpenURL(URL(string: url)!) {
if #available(iOS 10.0, *) {
application.open(URL(string: url)!, options: [:], completionHandler: nil)
}
else {
application.openURL(URL(string: url)!)
}
return
}
}
}
}


Related Topics



Leave a reply



Submit