UIApplication sharedapplication openURL not working - ios

I have this method
- (IBAction)facebookButtonPress:(id)sender {
NSLog(#"fb hit");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[#"www.facebook.com/asbreckenridge" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
}
and I don't understand why safari doesnt open the link. I get the 'fb hit' logged, so the method is being called, but it doesnt open the link in Safari, what am I doing wrong?

Try it without the encoding like this.
- (IBAction)facebookButtonPress:(id)sender {
NSLog(#"fb hit");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"www.facebook.com/asbreckenridge"]];
}
Also try changing the URL to http://www.facebook.com/asbreckenridge

Try this:
- (IBAction)facebookButtonPress:(id)sender {
NSLog(#"fb hit");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.facebook.com/asbreckenridge"]];
}

In my case problem was in extra "/" at the end.
doesn't work:
#"http://www.facebook.com/asbreckenridge/"
works fine:
#"http://www.facebook.com/asbreckenridge"

Related

How to open applications like phone dialler on clicking tableview cell ios objective c

I am new in iOS development.
I have created a tableview menu which looks something like this :
Now I want to open the Phone Dialler, Messaging and Email app on cell tap. How to go about it ?
I was something like this ( DOESN'T WORK !!! ) :
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(self.tableView.indexPathForSelectedRow.row == 0){
NSLog(#"Call selected!!");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tell://1234"] options:#{} completionHandler:nil];
}
else if (self.tableView.indexPathForSelectedRow.row == 1){
NSLog(#"Text Selected!!");
}
else{
NSLog(#"Email Selected!!");
}
}
Any help will be appreciated.
Note : I am building on iOS 10.2 so methods like openURL are depreciated.
Thanks
You can initiate a call
[https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html][1]
is not tell://1234
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tell://1234"] options:#{} completionHandler:nil];
it is tel:1234
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:1234"] options:#{} completionHandler:nil];
or use
telprompt gives the user a choice to place the call or cancel making the call before the phone dials. The two forward slashes after the colon are optional.
for e.g
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt://1234"] options:#{} completionHandler:nil];
dont forget to add LSApplicationQueriesSchemes in your .plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
<string>telprompt</string>
</array>
for more information you can get the link for tutorial

How to open an https Facebook page from iOS device?

Im trying to open my Facebook app page from iPhone.
Im using this:
[[UIApplication sharedApplication] openURL:[NSURL
URLWithString:#"http://www.facebook.com/(my page name)"]];
Unfortunately, this redirects to https protocol, and because of that the device is unable to open the page.
What can I do to open this page?
pass your Page ID - xxxxxx not the page Name
[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"fb://profile/herepassyourPageID"]];
or
[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://www.facebook.com/herepassyourPageID (id, not name)"]];
You are mistaken by using page name instead of page ID.
You should use something like below:
NSURL *facebookURL = [NSURL URLWithString:#"fb://profile/{pageid}"];
if ([[UIApplication sharedApplication] canOpenURL:facebookURL]) {
[[UIApplication sharedApplication] openURL:facebookURL];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#""https://www.facebook.com/{pageid}"]];
}
[If desired]: You should check the availability of installed facebook app to open the page, as shown in the above code sample.

Custom URL link for linked in app

I am trying to open, linkedin app from my ios app. It is getting opened but with the user's home page. I want it to open with some profile. How can i send the profile id or name with custom url.
try this:
NSString *actionUrl = #"linkedin://#profile/52458178";
NSString *actionUrlWeb = #"http://www.linkedin.com/in/chetankedawat";
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:actionUrl]];
if (canOpenURL){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:actionUrl]];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:actionUrlWeb]];
}

Open and adding a Facebook page from ABUnknownPersonViewController

I've got this issue, I set up some contact information of a company to be displayed by a ABUnknownPersonViewController. One of the info is the Facebook page, if I click on it on the simulator it opens safari on the correct page. On the device the URL is intercepted by the FB app that doesn't open nothing but my timeline.
I'm aware that the same happens when you try to open an FB page URL inside the app using the method -openURL: and I know that this could be easily fixed by using that snippet.
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/pagename"]];
}
The fact is that I've tried to intercept the URL by using that app delegate method - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
(handleOpenURL: is deprecated), but it doesn't seems to be called.
Is there a way to intercept this opening?
I've found an answer, using the protocol methods of ABUnknownPresonViewcontroller is possible to intercept some events. I must be honest and say that I still didn't know how to recognize different actions, but in this way it works.
- (BOOL)unknownPersonViewController:(ABUnknownPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
if (property == 46) { //46 seems to be number associated to the property facebook page
NSURL * facebookURL = [NSURL URLWithString:#"fb://profile/PAGE_ID"];
if ([[UIApplication sharedApplication] canOpenURL:facebookURL]) {
[[UIApplication sharedApplication] openURL:facebookURL];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://facebook.com/PAGE_NAME"]];
}
return NO;
}
return YES;
}

ios Calling is not available

How do I know that I can not call from the device? For example for e-mail: [MFMailComposeViewController canSendMail]
Anything for calling?
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tel:+123456"]]) {
...
}
This can be used for calling :
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:12125551212"]];
Please refer this link for more:
iPhoneURLScheme Reference

Resources