NSString *phoneNumber = @“12345678910”
第一种方式 if (phone != nil) {
NSString *telUrl = [NSString stringWithFormat:@"telprompt:%@",phoneNumber];
NSURL *url = [[NSURL alloc] initWithString:telUrl];
[[UIApplication sharedApplication] openURL:url];}
第二种方式 (这种方式在挂断电话之后会返回到通讯录界面)
在点击打电话按钮时才会触发,因此点击的时候创建callWebView即可,可以将callWebView定义为属性,然后
重写getter方法实现懒加载.当然定义为属性之后还要重写dealloc方法.这样就能实现内存的安全处理
//定义属性
@interface
@property (nonatomic, retain) UIWebView *callWebview;
@end
//重写getter方法
- (UIWebView *)callWebview
{
return [[_callWebview retain] autorelease];
}
触发事件方法内部
NSString *telUrl = [NSString stringWithFormat:@"tel:%@",phoneNumber];
NSURL *telURL =[NSURL URLWithString:telUrl];
if (!_callWebview) {
self.callWebview = [[[UIWebView alloc] init] autorelease];
}
[self.callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
[self.view addSubview:_callWebview];//添加到view上
IOS中打电话的两种方式代码实现
最新推荐文章于 2022-03-28 17:39:48 发布