下面是拨打电话的代码,按钮的触发事件
@property (nonatomic ,strong) UIAlertView *alertView;
- (IBAction)CallphoneBtn:(id)sender {
//用户体验
_alertView=[[UIAlertView alloc]initWithTitle:@"确定需要打电话?" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[_alertView show];
}
//alertView代理,别忘记遵守协议
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0)
{
// [_alertView cancelButtonIndex];
}
else
{
//这个是关键代码
NSString *number=@"132xxxxxxxx";
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",number]]];
}
}