How to make a phone call (programmatically) with the iphone (ios sdk)
this problem is very simple to solve, you will have to write only few lines of code. But you should also know some theory. We are going to solve this problem using NSURL, so a short overview (from Apple) about this class could be useful.
An NSURL object lets you manipulate URLs and the resources they reference. The URLs employed by the NSURL class are described in RFCs 1808, 1738, and 2732. The litmus test for conformance to RFC 1808 is as recommended in RFC 1808—specifically, whether the first two characters of resourceSpecifier are slashes (//).
You can use an NSURL object to refer to a file, which is the preferred way to do so. AppKit objects that can read data from or write data to a file generally have methods that accept an NSURL object instead of a pathname as the file reference. In Mac OS X, the NSWorkspace class provides openURL: to open a location specified by a URL. Similarly, in iOS, UIApplication provides openURL:. To get the contents of a URL, NSString provides stringWithContentsOfURL: and NSData provides dataWithContentsOfURL:.
An NSURL object is composed of two parts—a potentially nil base URL and a string that is resolved relative to the base URL. An NSURL object whose string is fully resolved without a base is considered absolute; all others are considered relative.
The classes NSURLConnection and NSURLDownload define methods useful for loading URL resources in the background. See URL Loading System Programming Guide for more information
Let's go on, writing some code:
// Set into a string the phone number you want to call
NSString *phone_number = "012-12345678";
// Create a string with the correct format <tell://> <phone number>
NSString *phoneStr = [[NSString alloc] initWithFormat:@"tel://%@",phone_number];
// Prepare the NSURL
NSURL *phoneURL = [[NSURL alloc] initWithString:phoneStr];
// Make the call
[[UIApplication sharedApplication] openURL:phoneURL];
See you soon,