XCode - FB URL Schemes Not Working - ios

I have the following code in my iOS app, attempting to open up a user's Facebook page in the app:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"fb://profile/%#",fbidStr]];
[[UIApplication sharedApplication] openURL:url];
if ([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"https://www.facebook.com/%#",fbidStr]]];
}
When the app opens, I get an error 'The page you requested was not found'. I've NSLogged the URL and it looks fine:
fb://profile/10154531xxxxx65245
And everything works fine when the user doesn't have the app installed and views the profile in safari.
What could be wrong here?

I've had the some problem, it seems that Facebook only accepts on their profile module people that are already friends with you.

Related

openUrl is not redirecting to safari in iOS 8.3

I have my old application which is working fine till iOS 8.2. In one button action I have to open safari using openUrl and this is working fine for the device with iOS 8.2. But when I run it in iOS 8.3 then its not opening the safari and when I tried to print it then its returning NO.
Is there any change in iOS 8.3 for openUrl method?
Edit 1:
NSString *loginUrl=[object sighnUpUrl];
NSLog(#"%d",[[UIApplication sharedApplication] openURL:[NSURL URLWithString:loginUrl]]);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:loginUrl]];
I am just using the url of login page of my web.
Edit 2:
NSURL *url = [NSURL URLWithString:#"http://www.stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(#"%#%#",#"Failed to open url:",[url description]);
}
I tried the same code and getting Failed to open url:http://www.stackoverflow.com.
Edit 3:
NSURL *URL = [NSURL URLWithString:#"http://www.google.de"];
if ([[UIApplication sharedApplication] canOpenURL:URL]) {
[[UIApplication sharedApplication] openURL:URL];
}
When I tried the same above code then its entering the if block but still unable to the safari.
Note: All the above Codes are working in iOS 8.2.
this is the way to go:
NSURL *URL = [NSURL URLWithString:#"http://www.google.de"];
if ([[UIApplication sharedApplication] canOpenURL:URL]) {
[[UIApplication sharedApplication] openURL:URL];
}
Check this
NSURL *url = [NSURL URLWithString:#"http://www.stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(#"%#%#",#"Failed to open url:",[url description]);
}
Please try this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
Edit:
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:yourURL];
Try to place your URL here & check whether it returns True or False.
I have gone through all the answers and I know all of them will work.The issue was on the other side.I am using Mobile Device Management in my app.Some one from the server side had disabled safari using MDM.Unfortunately for the device with iOS 8.2 it was enabled and for the devices with iOS 8.3 it was disabled which made me think its an iOS issue.So while safari is disabled using MDM it can't open any url.My Bad.Thanks for all your answers.
ios8.3 .apk file received by e-mail, can not open other applications, it may be a BUG ios8.3 of

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.

open Facebook page from the app

I was trying to open the Facebook app with particular Facebook page from my app with the following code:
NSURL *url = [NSURL URLWithString:#"http://www.facebook.com/pagename"];
[[UIApplication sharedApplication] openURL:url];
When I click on the button it opens the Facebook app but the required page doesn't load or show.
Is there any other way to open the Facebook app with particular Facebook page? Please correct me If I am doing something wrong.
Thanks in advance.
To open the facebook app directly you should do the following:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString: #"fb://profile/PAGE_ID"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"fb://profile/PAGE_ID"]];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://facebook.com/PAGE_NAME"]];
}
This is a solution including a fallback for web.
To determine your PAGE_ID you could use a service like this.

alternative to openUrl for sms and calling

Is this is the only way to open a dialer to call or msg.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:+%#",phoneNumber]]];
if yes. then will this support from ios3 to ios6 (beta).
if no. then can any one please give some sample code.(if any private api can do this pls mention it)
if separate functions are available for sending sms and calling a number, please let me know that too.
in ipad 1 with ios 4.2.6, the following codes are not working
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"sms:9190432097420"]]];
and
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel:9190432097420"]]]
Wr does the problem lies
According to UIApplication's Class Reference, the openUrl: method is available in iOS 2.0 and later. So you should be safe to use that method.
With regard to your example, it's 'safer' if you first check if there is an application that can handle the provided url. For instance:
NSURL *url = [NSURL URLWithString:#"tel:9190432097420"];
if([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
else {
NSLog(#"No application for url '%#'", url);
}
Are you testing on an actual device or in the simulator? The simulator does not support this as far as I've seen.

Resources