我试图通过以下方式从ios应用程序拨打电话号码:虽然方法被调用,但它无法正常工作:
-(IBAction)callPhone:(id)sender {
NSString *phoneCallNum = [NSString stringWithFormat:@"tel://%@",listingPhoneNumber ];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneCallNum]];
NSLog(@"phone btn touch %@", phoneCallNum);
}
Run Code Online (Sandbox Code Playgroud)
NSLog 输出:手机btn touch tel:// + 39 0668806972
小智 89
你的代码是正确的.你检查过真正的设备吗?此功能在模拟器中不起作用.
试试这个,
NSString *phNo = @"+919876543210";
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",phNo]];
if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
[[UIApplication sharedApplication] openURL:phoneUrl];
} else
{
calert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Call facility is not available!!!" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[calert show];
}
Run Code Online (Sandbox Code Playgroud)
**Swift 3版**
if let url = URL(string: "telprompt:\(phoneNumber)") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.openURL(url)
}
}
Run Code Online (Sandbox Code Playgroud)
Ama*_*mar 14
电话无法在模拟器/ iPod/iPad上运行,您需要在具有活动SIM卡的iPhone上运行该应用程序.
还有用于调用电话应用程序的URL方案tel:<phone_number>.请参阅Apple文档.
理想情况下,您应检查设备是否具有电话模块,然后执行openURL:呼叫.使用此代码执行检查,
if([[UIApplication sharedApplication] canOpenURL:callUrl]) {
[[UIApplication sharedApplication] openURL:callUrl];
}
else {
//Show error message to user, etc.
}
Run Code Online (Sandbox Code Playgroud)
使用以下方法拨打电话:
NSString *phoneNumber = [@"tel://" stringByAppendingString:number];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
50630 次 |
| 最近记录: |