PDA

View Full Version : Programmatically dialing a number and sending an email?




code.warrior
Feb 25, 2009, 12:27 AM
Hi,

This might be a very simple thing for iPhone development purpose, but, sadly, though, I haven't been able to properly figure out how to programmatically dial a phone number and invoke the emailing phone applications, from my native application!

I've tried using the Apple URL schemes, in this regard, but it didn't help me much.
For dialing a number I'm using the following code:

NSString *callToURLString = [NSString stringWithFormat:@"tel:%@", [(UIButton*)sender currentTitle]];
if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:callToURLString]])
{
// there was an error trying to open the URL. We'll ignore for the time being.

}
where currentTitle is the telephone number I want my application to dial. But all its doing is throw an alert:
Unsupported URL. The URL wasn't loaded: tel:9xx-xxx-xxxx
I've even tried tel://<tel. number> instead of tel:<tel. number> thinking that the scheme might have changed after iPhone OS 2.0 release, but to no avail.
The same is with the email app, invocation. I'm using the the following code for that purpose:

NSString *emailIDString = [NSString stringWithFormat:@"mailto:%@", [(UIButton*)sender currentTitle]];
if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:emailIDString]])
{
// there was an error trying to open the URL.
//for the time being we'll ignore it.
}

where again currentTitle is the email id I want my application to mail to. Its throwing me the same alert. I've even tried mailto://<email-id>, with no success.
I'm referring to the following the documentation in this regard:
https://developer.apple.com/iphone/library/featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html

What am I doing wrong over there? Kindly enlighten me.


Thanks for reading through.



jnic
Feb 25, 2009, 03:50 AM
Just to check; you're doing this on the device and not in the simulator, right?

code.warrior
Feb 25, 2009, 04:20 AM
Just to check; you're doing this on the device and not in the simulator, right?

oh, my bad, I just got to know that, it doesn't work on simulator.
Oh well, but I was wondering if there is any way, to do this on simulator? or is that, these phone functionalities ain't present on simulator itself?

jnic
Feb 25, 2009, 04:28 AM
Not to my knowledge. The simulator doesn't have the Phone or Mail apps so can't support either of those URL schemes. You ought to test on a device before submission anyway, since there are differences in behavior and limitations between the two.

code.warrior
Feb 26, 2009, 02:01 AM
Not to my knowledge. The simulator doesn't have the Phone or Mail apps so can't support either of those URL schemes. You ought to test on a device before submission anyway, since there are differences in behavior and limitations between the two.

Yeah, thats alright. I was wondering whether we can test the features first on the simulator and then test it on the actual device. That would have been bit better, since my application is under development and this requirement is just one feature, along with several others which will be required to complete before testing it on actual device.

anyways, Thanks alot for the information, appreciate it.

priyank.ranka
Mar 21, 2009, 06:08 AM
I have include the message framework in my application but whn install on the phone whn trigger the mailto option it does not work.. is some thing we have to install on the phone for making it work