【发布时间】:2012-03-05 07:57:19
【问题描述】:
我正在做一个生日剩余申请。在那我提供了一个文本字段来输入手机/电话号码。底部我提供了一个按钮,如果我们按下该按钮呼叫需要继续到文本字段中给出的数字。我试过但我无法做到这一点。任何人都可以帮助我编码。谢谢!
【问题讨论】:
我正在做一个生日剩余申请。在那我提供了一个文本字段来输入手机/电话号码。底部我提供了一个按钮,如果我们按下该按钮呼叫需要继续到文本字段中给出的数字。我试过但我无法做到这一点。任何人都可以帮助我编码。谢谢!
【问题讨论】:
试试这个
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",self._phoneNumber]];
[[UIApplication sharedApplication] openURL:url];
仅适用于 iphone,必须实现您自己的警报委托方法。
【讨论】:
试试这个。
-(void) makeCall{
NSString* phoneNumber=yourTextFiled.text;//TextFiled
NSString *phoneNumber = [NSString stringWithFormat:@"%@",phoneNumber];
NSURL* callUrl=[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNumber];
//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];
}
}
希望对你有帮助。
【讨论】:
[[UIApplication sharedApplication] canOpenURL:] 方法。如果您使用电话号码 URL 调用此方法,它将在无法拨打电话的设备上返回 NO。
请检查这 2 个链接:
来电号码: Programmatically Dial a Phone number and pass DTMF using the iPhone SDK
以及为什么不从文本字段中获取价值: iPhone SDK: how to get the value of a UITextField in an alert?
【讨论】: