iPhone Programming Tips: Dialing number, opening Email & SMS applications

Introduction

iPhone SDK did not gives you full control over iPhone functionality. But there are few things you can do using iPhone SDK, like, you can dial a number from your application, you can open an email and SMS client from your application.

Request Full Filled

This tutorial is for Sudha who requested for this in “Request iPhone Tutorial” section (Note: any one can request for iPhone tutorial there).

Dial Number:

When you dial some number from your application then your application will go in background and in ideal state.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123123"]];

Open Email application:

You can’t attached anything with email in SDK 2.2.1 or below. But in iPhone SDK 3.0 you can open an email client from within your application.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto:emailAdress?subject=testMail&body=its test mail."]];

Open SMS application:

You can not provide text for SMS
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:111"]];

You can grab the code from here. First select the contact from your address book and then click on bottom buttons.
[Note: If you run this code from simulator then it will not show you anything. So please install this application on your iPhone/iPod device and then test it.]

This is a guest post by Zubair Daud, an iPhone developer. Click here to find out more about him.

Popularity: 44% [?]

6 Comments on "iPhone Programming Tips: Dialing number, opening Email & SMS applications"

  1. Sudha says:

    Thanks a lot for the post!!!

    This is so helpful.

    Could you explain how the SMS works in the app? I don’t have iPhone to test the code now, using the simulator.

    Thanks again!

    CS Rededy

  2. Sudharshan says:

    Hi Adeem,

    The call and text code is not working in some phones that are upgraded to 3.0 from lower version.

    Is there any limitations/changes to the code depending on the version?

    Thanks,
    Sudharshan

  3. Sudharshan says:

    Found the problem!!
    It was because we were trying to dial the number in US phone number format like (123) 456-7890.
    The problem is because of the black space after braces.

    Thanks,
    Sudharshan

  4. jissa says:

    Hi Adeem,
    is there any way to open the mail box from my app?
    if yes, please send me some code.

  5. iAndrew says:

    Hi Adeem,
    Could you please do a tutorial about youtube url implementation?
    It’s very important because without i can’t continue my project.
    I will be grateful you.

    Sincerely,Andrea

  6. Martin says:

    Hi Adeem!

    Nice blog!
    Just wanted to tell you, that since iPhone OS 3.0b you don’t need to open the Mail app anymore, you can compose and sent mail directly from within your own app! Just use MFMailComposeViewController ;-)

    - Martin

Got something to say? Go for it!