在做通讯录功能时,有需求要点击按钮直接调用系统拨打电话和发送短信的功能,然后上网查了一下,有以下方法:
点击按钮实现拨打电话
- 方法1:点击按钮后不弹出提示,直接拨打
// 点击按钮拨打电话
- (IBAction)dialPhoneNumber:(UIButton *)sender
{
NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"186xxxx6979"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
- 方法2(推荐):点击按钮后会弹出提示是否需要拨打,打完电话后会回到原来的程序
// 点击按钮拨打电话
- (IBAction)dialPhoneNumber:(UIButton *)sender
{
NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"186xxxx6979"];
UIWebView *callWebview = [[UIWebView alloc] init];
[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
[self.view addSubview:callWebview];
}
- 方法3:效果与2一样,但是网上说这个方法可能不合法 无法通过审核(不知道是不是真的)
网上说:
// telprompt协议属于苹果的私有协议,一旦程序中使用了此协议,程序无法上架
// 针对越狱的机器开发的系