How can I make phone call in iOS? - ios

How can I make a phone call in Objective-C?

You can initiate a call
https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/PhoneLinks/PhoneLinks.html
So this would probably work:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:12125551212"] options:#{} completionHandler:nil];

This is clipped from a project I did to do just that:
NSString *phoneStr = [NSString stringWithFormat:#"tel:%#",phone_number];
NSURL *phoneURL = [NSURL URLWithString:phoneStr];
[[UIApplication sharedApplication] openURL:phoneURL];

It may also be helpful to know how to prompt the user to call a number:
NSURL *phoneNumber = [NSURL URLWithString:#"telprompt://13232222222"];
[[UIApplication sharedApplication] openURL:phoneNumber];
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.

well if you are talking about using objective-c to make a phone call on the iphone, then you can do something like this:
NSURL *phoneNumber = [[NSURL alloc] initWithString: #"tel:867-5309"];
[[UIApplication sharedApplication] openURL: phoneNumber];
If you are talking about doing this on a mac ,well, then like others have mentioned that is specific based on number of things like, if you are using voip, a modem, connecting through something like an Asterisks box, etc..

openURL is deprecated.
Now use this:
UIApplication *application = [UIApplication sharedApplication];
[application openURL:[NSURL URLWithString: #"tel:12125551212"] options:#{} completionHandler:nil];

REMOVE EMPTY SPACES IN PHONE NUMBER
NSString *phoneNumberString = #"123 456";
phoneNumberString = [phoneNumberString stringByReplacingOccurrencesOfString:#" " withString:#""];
phoneNumberString = [NSString stringWithFormat#"tel:%#", phoneNumberString];
NSURL *phoneNumberURL = [NSURL URLWithString:phoneNumberString]];
[[UIApplication sharedApplication] openURL:phoneNumberURL];

NSString *phoneNumber = #"Phone number here";
UIWebView *webView = [[UIWebView alloc] init];
NSURL *url = [NSURL URLWithString:numberString];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
webView.dataDetectorTypes = UIDataDetectorTypeNone;
[webView loadRequest:requestURL];

This will either be very platform-specific, or you'll have to use a wrapper library to account for the differences among platforms, so you better state what platform this is intended for. In general, there are various telephony APIs available on most platforms.
On Windows systems there's for example the "TAPI", also things may somewhat differ if you are targeting a digital telephone system such as ISDN, because there are other APIs available.

Related

opening a received url with safari

I am receiving a url from a server request, I made a button , when pressed, safari must open and go to the link,
My code below:
- (IBAction)openFeedbackWebViewPresser:(id)sender {
NSString *feedbackUrl = self.getConfig.feedbackURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];
}
If I print the feedback url , its as below:
https://xxx.xxxxx.com/CRM/feedback#/1715171559ae979371687#/10306
I tried to use another way:
NSURL *url = [NSURL URLWithString:feedbackUrl];
[[UIApplication sharedApplication] openURL: url];
the url is returning nil, knowing that the feedbackUrl contains a url.
Any idea whats wrong?
Thanks
Might be your string url is containing any spaces or any other special characters that must be encoded. like below
NSString *feedbackUrl = [self.getConfig.feedbackURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];
hope it helps.!!!
This might be happening because of the special characters that must be encoded. The following encoding works for me-
NSString *feedbackUrl = [self.getConfig.feedbackURL stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: feedbackUrl]];
This is the code to open the link in browser, Hope this help
- (IBAction)emailButton:(id)sender {
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:self.emailLabel.text]];
}

Make a phone call from UIWebView without prompt

SCENARIO
I have an app that is a UIWebView, I make some url overriding for requirements.
PROBLEM
To make a call opening url with tel: works weird in iOS7 and iOS8, it makes the phone call direct in the background, but it also ask for the confirmation, so user experience is horrible:
[[UIApplication sharedApplication] openURL:request.URL];
SOLUTION
To solve this issue, I used telprompt. It works nice in all iOS versions:
NSURL *url = [NSURL URLWithString:#"telprompt://637****"];
return [[UIApplication sharedApplication] openURL:url];
But shows this confirmation dialog:
QUESTION
Now, I have a new requirement, to make the phone call without confirmation or prompt. So... There is some way to make a phone call in iOS omitting the confirmation prompt?
I want something like
NSURL *url = [NSURL URLWithString:#"telnoprompt://637******"];
return [[UIApplication sharedApplication] openURL:url];
NSMutableCharacterSet *characterSet =[NSMutableCharacterSet characterSetWithCharactersInString:#" "];
NSArray *arrayOfComponents = [phone_number componentsSeparatedByCharactersInSet:characterSet];
phone_number = [arrayOfComponents componentsJoinedByString:#""];
NSString *phoneURLString = [NSString stringWithFormat:#"tel:%#", phone_number];
NSString *escapedUrlString = [phoneURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *phoneURL = [NSURL URLWithString:escapedUrlString];

IOS SMS Sending using UI Shared Application

I cannot pass phone number to SMS.
NSString *myString = lblMobilePhone.text;
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:[NSString stringWithFormat:#"sms://%#",myString]]];
MFMessageComposeView is how you should be doing it.
If you want to do it your way you need to change it to [NSString stringWithFormat:#"sms:%#",myString] (removed the two // from the url)

Sygic URL scheme - App does not open

I am trying to integrate the most popular navigation apps into my app, and all of those I chose work, except for Sygic.
Following this guide, I wrote the code:
NSString *URL = [NSString stringWithFormat:#"com.sygic.aura://coordinate|%f|%f|drive",
self.coordinate.longitude,
self.coordinate.latitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URL]];
But when the code is run, Sygic doesn't open, nothing happens.
Checking [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"com.sygic.aura://"]] returns YES when the app is installed and NO when it's not (as it should).
I tested using "Sygic Brasil" and "Sygic (All Regions)", version 13, but neither will open.
I also tried percent-escaping the URL string, and that didn't work either.
you try following code,
NSString *URL = [NSString stringWithFormat:#"com.sygic.aura://coordinate|%f|%f|drive",
self.coordinate.longitude,
self.coordinate.latitude];
NSURL *newURL = [NSURL URLWithString:[URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ];
if(newURL)
{
[[UIApplication sharedApplication] openURL:newURL];
}
else
{
NSLog(#"Something wrong with lat or long or both");
}

Easiest way to share a link as Page from iOS app

What's the easiest way to share a link as a Facebook Page from an iOS app? I don't care if the solution isn't elegant, it's just for an internal tool.
You can try this....
NSString *urlString = #"Your Link";
NSString *shareUrlString = [NSString stringWithFormat:#"https://m.facebook.com/sharer.php?u=%#", urlString];
shareUrlString = [shareUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [[NSURL alloc] initWithString:shareUrlString];
[[UIApplication sharedApplication] openURL:url];

Resources