Open Facebook url in Safari instead of native app - ios

is there any way to open Facebook url (ex. http://www.facebook.com/facebook) in Safari instead of native app? I'm tried to do this:
NSURL *url = [NSURL URLWithString:#"http://www.facebook.com/facebook"];
[[UIApplication sharedApplication] openURL:url];
but iOS automatically launch native client (of course if it's installed) if you try to open url with in facebook domain. thanks.

Ok, I think I found answer, you must replace "www.facebook.com" with "facebook.com" in url.
Something like this:
NSString *facebookUrlString = #"http://www.facebook.com/facebook";
if ([[facebookUrlString pathComponents] count] > 0) {
if ([[facebookUrlString pathComponents][1] isEqualToString:#"www.facebook.com"]) {
NSMutableArray *pathComponents = [[facebookUrlString pathComponents] mutableCopy];
[pathComponents replaceObjectAtIndex:1 withObject:#"facebook.com"];
facebookUrlString = [NSString pathWithComponents:pathComponents];
}
}
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:facebookUrlString]];

Copy link to the messenger app and send to yourself. Open the link on messenger app and click on share and will apear open with facebook app

Related

URL for facebook?

Can I know the code for facebook application? for example https://www.facebook.com/nike/?fref=ts .. I tried it bit it didn't work. I tried it with the youtube code but it didn't work!
For example for youtube
-(IBAction)btnYoutube:(id)sender {
NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:#"youtube://user/%#",#"toyotaleasing"]];
NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.youtube.com/user/%#",#"toyotaleasing"]];
if ([[UIApplication sharedApplication] canOpenURL:linkToAppURL]) {
// Can open the youtube app URL so launch the youTube app with this URL
[[UIApplication sharedApplication] openURL:linkToAppURL];
}
else{
// Can't open the youtube app URL so launch Safari instead
[[UIApplication sharedApplication] openURL:linkToWebURL];
}
}
Does anyone know?
If you see the log in console it will show below log :
-canOpenURL: failed for URL: "youtube://user/toyotaleasing" - error: "This app is not allowed to query for scheme youtube"
The solution is, you need to "whitelist" all your URL schemes which will be used in your app, list down in info.plist.
info.plist key for this is "LSApplicationQueriesSchemes".
This is how your info.plist look like when you add "youtube" as scheme.
Now it will work.

Link from iOS app to website

I am looking to link my iOS app to my website. I want the link to open the safari web browser. Currently the link goes to the website but stays in the app.
Here is what I am using:
<a onclick="window.location.href='http://www.website.com/folder/page.php';">Contact</a>
Any suggestions?
To open a webpage in device's browse, use following code
NSURL *strURL = [[NSURL alloc] initWithString:#"http://www.website.com/folder/page.php"];
if ([[UIApplication sharedApplication] canOpenURL:strURL]) {
[[UIApplication sharedApplication] openURL:strURL];
} else {
NSLog(#"Cann't open url : %#",strURL);
}

How to open App in iOS using "appname://openApp?"?

I need to open another app with parameters from my iOS App.
I have specific URL scheme provided from the developers of the App that have to be opened:
secondApp://openApp?param1=XXX&param2=YYY
I try to search Google how to open App in this way but I did not found any example how to use this construct.
Can you provide me with link or a row of code how to open App in this way?
You can look into this documentation of Inter-App Communication provided by Apple. Also, you can look into this tutorial. Here, they are sending text to another app. Also, another detailed answer to your question can be found in here.
Following code from the tutorial will help you :
-(IBAction) openReceiverApp {
// Opens the Receiver app if installed, otherwise displays an error
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *ourPath = #"secondApp://openApp?param1=XXX";
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL]) {
[ourApplication openURL:ourURL];
}
}
To open second app from your iOS app, just use:
NSURL *url = [NSURL URLWithString:#"secondApp://openApp?param1=XXX&param2=YYY"]; //fill your params
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}

can we force to open facebook link in browser not in native app iphone

Is it possible to force through your application that it will open the web link in safari only not in native app like facebook, twitter or web view etc.
So far i searched found only this code that is used for opening the link
NSURL *url = [NSURL URLWithString:#"www.facebook.com"];
[[UIApplication sharedApplication] openURL:url];
But what can we paste in else there below?
if ([[UIApplication sharedApplication] canOpenURL:nsurl]){
[[UIApplication sharedApplication] openURL:nsurl];
}
else {
//Open the url as usual, but how?
}
Use http://facebook.com/ instead of www.facebook.com
this will force a link to open in Safari instead of native app*
NSURL *myURL = [NSURL URLWithString:#"http://facebook.com/"];
if ([[UIApplication sharedApplication] canOpenURL:myURL]) {
[[UIApplication sharedApplication] openURL:myURL];
}
You can use a webView to open any link of your choice.

Facebook App does not display page when linked from iOS App

I'm working on iOS application. Here is the code i used
NSURL *url = [NSURL URLWithString:#"fb://page/5718758966"];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
else
{
//Open the url as usual
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://facebook.com/5718758966"]];
}
As I mentioned, this code has worked to open Facebook app but shows blank page; my question is if there is an alternative link I can use that will both open the app and direct the user to this specific page, or is this simply a Facebook bug?
Thanks!
Instead of "fb://page/5718758966" try "fb://profile/5718758966" for your URL.

Resources