问题
Possible Duplicate:
make a call in iphone from my application
I want to make a phone call on given number from my iPhone application. Could you suggest any good tutorial which explains it the best or tell me the process?
回答1:
NSString* phoneNumber=TextFiled Name
NSString *number = [NSString stringWithFormat:@"%@",phoneNumber];
NSURL* callUrl=[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",number]];
//check Call Function available only in iphone
if([[UIApplication sharedApplication] canOpenURL:callUrl])
{
[[UIApplication sharedApplication] openURL:callUrl];
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"ALERT" message:@"This function is only available on the iPhone" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
回答2:
You can try :
NSURL *phoneNumberURL = [NSURL URLWithString:@"tel:80001212"];
[[UIApplication sharedApplication] openURL:phoneNumberURL];
回答3:
Try this:-
NSString *phoneNumber = @"15555551212";
NSString *dtmfAfterPickup = @"1234";
NSString *telString = [NSString stringWithFormat:@"tel:%@,%@", phoneNumber, dtmfAfterPickup];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:telString]];
回答4:
Opening an app from within another app is managed in iOS through the "url scheme" mechanism. If an app defines an url scheme, and this scheme is public, you can then use it to run that app. Basic rule is to first check that your device supports that scheme (e.g. you cannot make a phone call on an iPad because the phone app is not installed) and then, if the answer is positive, call it:
if([[UIApplication sharedApplication] canOpenURL:myURL]) {
[[UIApplication sharedApplication] openURL:myURL];
} else {
// do something else, e.g. inform the user that he/she cannot open the app
}
This check is important as for some schemes, e.g. the phone one, the system checks is the url is well formed or not. E.g.: for phone numbers space between digits is not supported.
The most common Apple URL schemes are described here: http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html#//apple_ref/doc/uid/TP40007893-SW1 In particular, the telephone url scheme is here: http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html#//apple_ref/doc/uid/TP40007893-SW1
Finally there is a web site, called handleOpenURL that is trying to collect all apps url schemes. If you define an app that exposes an url scheme and you want it to be public, don't hesitate to post it in this site.
回答5:
There are two ways to acheive this:-
1) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://9912345678"]];
2) You can use the UITextView
and enable phone detection. After that the phone number will look like hyperlinked. Use the following code.
mytextview.text = @"9943586256";
mytextview.dataDetectorTypes = UIDataDetectorTypePhoneNumber;
mytextview.editable=NO;
Helpful if you want to show the phone number inside a custom tableview cell.
I would personally like the second one due to requirements in some project. When i have give the telephone number in UITextView
and upon pressing that will start the calling.
来源:https://stackoverflow.com/questions/9732043/make-calls-from-iphone-app