自己写的拨打电话的代码
#pragma mark - telAction
- (void)telAction
{
// 进入拨打电话页面
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"服务时间:工作日 09:00-17:30" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:[NSString stringWithFormat:@"呼叫:%@-%@-%@",[kCustomerService substringToIndex:3],[kCustomerService substringWithRange:NSMakeRange(3, 3)],[kCustomerService substringFromIndex:6]] otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
[actionSheet showInView:self.view];
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [actionSheet cancelButtonIndex]) {
NSString *URLString = [NSString stringWithFormat:@"tel://%@", kCustomerService];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:URLString]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URLString]];
} else {
[self toast:@"当前设备中没有通话功能"];
}
}
}
本文介绍了一个简单的iOS应用中实现拨打电话功能的方法。通过使用UIActionSheet展示可供选择的电话号码,并在用户确认后调用系统拨号界面。如果设备不支持拨打电话,则会提示用户。
2051

被折叠的 条评论
为什么被折叠?



