加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iOS调打电话代码

发布时间:2020-12-16 07:43:20 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 // 定义点击拨号按钮时的操作 - (void)callAction{ NSString *number = @"";// 此处读入电话号码// NSString *num = [[NSString alloc] initWithForma

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

// 定义点击拨号按钮时的操作 

- (void)callAction{ 

NSString *number = @"";// 此处读入电话号码

// NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",number]; //number为号码字符串 如果使用这个方法 结束电话之后会进入联系人列表

 

NSString *num = [[NSString alloc] initWithFormat:@"telprompt://%@",number]; //而这个方法则打电话前先弹框  是否打电话 然后打完电话之后回到程序中 网上说这个方法可能不合法 无法通过审核

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]]; //拨号

}

 

// 下面的代码能在应用中添加一个电话按钮,点击即可拨打电话号码。对于 iPhone 开发者还是很有用的。

// 添加电话图标按钮 

UIButton *btnPhone = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 

btnPhone.frame = CGRectMake(280,10,30,30); 

[btnPhone setBackgroundColor:[UIColor redColor]];

// 点击拨号按钮直接拨号 

[btnPhone addTarget:self action:@selector(callAction) forControlEvents:UIControlEventTouchUpInside]; 

[self.window addSubview:btnPhone];

 

//  第三种方式打电话

 

-(void)CallPhone{

NSString *phoneNum = @"";// 电话号码

NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];  

if ( !phoneCallWebView ) {          

phoneCallWebView = [[UIWebView alloc] initWithFrame:CGRectZero];// 这个webView只是一个后台的容易 不需要add到页面上来  效果跟方法二一样 但是这个方法是合法的

} 

[phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];

}

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读