Make a Call from UITableViewCell - iphone

I stuck with a problem.
In my tableView I got a cell with a phone number. I would like to click on the phone number and make a call.
I implemented the following in didSelectRowAtIndexPath:
NSString *cifra=#"tel://123456789";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:cifra]];
NSLog(#"after call %#",cifra);
Unfortunatly it doesnt do anything. In my log it shows me my "after call ... " but it is not calling. No error, no log, no action :(
It works for me with opening a website or googleMaps, but not for calling.
Is there anything i can do?
Maybe a it is simple answer, but i really dont know what to do. Is there a different way to make a call?
I am using the iPhone Simulator. Is this the problem? But it should do a thing, shouldn't it? :)
Thanks for your help!

You can't make calls from the Simulator.
If you want to test making a phone call, run the app on your device, then press the cell to make a phone call on your actual device.
You can simulate the in-call status bar, but there is nothing actually happening when it comes to actual phone calls.
Hardware > Toggle In-Call Status Bar
Note that using [[UIApplication sharedApplication] openURL:SOMEPHONENUMBER]; does not trigger this event.

Tried this code to make a call
NSString *prefix = (#"tel://(972)818-32432");
UIApplication *app = [UIApplication sharedApplication];
NSString *dialThis = [NSString stringWithFormat:#"%#", prefix];
NSURL *url = [NSURL URLWithString:dialThis];
[app openURL:url];

On top of the answers mentioning you can't make calls from the simulator, cifra should be #"tel:123456789", the double slashes aren't needed.

Related

Using Dialer for iOS app [duplicate]

I allow my user to select phone numbers in my application. How can I then bring up the iPhone call screen and then if possible, initiate the phone call?
You'll have to recreate the dial screen within your application (didn't take too long for me to do.) Once you have the phone number entered, you'll need to initiate the phone call by doing:
NSString* theNumberYouGathered = #"9994441234";
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: [NSString stringWithFormatting: #"tel:%s", theNumberYouGathered]]];
Note this will only work on the actual phone, and not the simulator.
To create the dialer screen you'll need to:
Create a xib file with a set of UIButtons (for #s 1-9), a UILabel to show the currently entered number, and a "Call" button.
Hook up the presses on the number UIButtons and add the digit to a local variable NSString on your ViewController. Update the UILabel with this number.
When the call UIButton is pressed, take the locally stored # and place the aforementioned method call with it.
You can do this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel:12125551212"]];
which will create a UIAlertView prompting the user to call the number or cancel.
You can use below code
NSString *phoneNumber = #"18000275749"; // dynamically assigned
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"telprompt://%#",phoneNumber]]];

UIButton does not perform phone call

Seems like this should be simple enough but for whatever reason I am unable to get the phone feature to prompt when my UIButton is pressed.
-(IBAction)viewMapButton:(id) sender
{
NSString *phoneNumber = [[NSString alloc] initWithString:#"tel:1234567890"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
NSLog(#"Call");
}
My NSLog is successfully called. I am running this just on the iOS simulator; is that causing it not to prompt to place the call?
Thanks!
Flea
The iOS simulator doesn't have a phone (just like the iPod Touch), so nothing will happen when you call the tel URL scheme.

How can I initiate a phone call programmatically on the iPhone in iOS 5?

How can I initiate a phone call programmatically on the iPhone in iOS 5? i tried the following code call functionality is working fine but when I click the cancel button, It is displaying black screen.
NSString *phoneUrl;
phoneUrl=#"9866510857";
NSString *phoneNumber = [#"tel://" stringByAppendingString:phoneUrl];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
1) Drop the // so you just have "tel:9866510857". I'm not sure if they hurt, but they definitely aren't necessary (see https://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html).
2) Make sure you aren't testing on the simulator; it doesn't have a phone app, so nothing will happen regardless. Test on an actual iPhone if you haven't been doing so.

How to return to my iphone application after call ends?

I am able to call from my iphone application by using below code:
NSString *phoneNumber = #"tel://1234567890";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Now, i want to know how to return to my application back when the call ends ?
UIWebView *phoneCallWebview = [[UIWebView alloc] init];
// [self.view addSubview:phoneCallWebview];
NSURL *callURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", 9238928399]];
[phoneCallWebview loadRequest:[NSURLRequest requestWithURL:callURL ]];
As far as I'm aware, such interaction is impossible since your application has been demoted to background, and all UI interaction has been delegated to the Phone app, and the user.
I found this SO question
End call, don't return to app automatic in iphone 3.1 version
Which pointed to an article on apple dev forums
https://devforums.apple.com/message/128046 (dev account required)
Which says it was a change in iOS 3.1 but a "workaround" is
use UIWebView to open the tel: url, after the call, your app will relaunch, but you get the annoying do you want to make this call alert.
I have't verified this works as described, just thought I'd point it out
From iOS 5, use below...
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:#"12345678"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Just use telprompt:// instead of tel://
telprompt will prompt the user first, and when call ends,it will go back to your application.
NSString *myNumber = [#"telprompt://" stringByAppendingString:txtMobileNo.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:myNumber]];

how do i launch the iphone sms text application in objective-c via the sms: url scheme?

I have a button in my obj-c application that I would like to launch the iphone text application when a button is pressed.
i've looked at the solution here How to use iPhone Custom URL schemes and have attached an action to my button (via the 'touch up inside' event), but the text app doesn't launch when the button is pressed.
here is my code
(IBAction)sendMsgBtnPressed:(id)sender {
NSLog(#"sendMsgBtnPressed");
NSString *stringURL = #"sms:+14155551212";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
[stringURL release];
}
i know this is being called because i can see the NSLog() output in my console. When I use a http:// scheme it works fine & launches Safari but sms: does not appear to work. Any idea what I am missing here?
Try removing the leading plus sign before the numbers in your url. The plus sign is used for international numbers and you can safely replace it with two leading zeroes. Moreover, be sure to provide a string in which no space occurs between numbers: something like
NSString *stringURL = #"sms:00141555 51212"; will NOT work correctly.
One more thing. The statement
[stringURL release];
is not correct because stringURL has not being retained. You should remove it from your method.
Notice that the SMS application will be opened ONLY in iPhone device - not simulator and not iPod Touch.
The SMS application doesn't exist on simulator and iPod Touch...
You can also check if the device can invoke the SMS app with
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:stringURL]]