IOS代码打电话

无错版:

@property (nonatomic,retain) UIWebView *callWebview;

//重写callWebview getter方法

- (UIWebView *)callWebview{

    if (!_callWebview) {

        self.callWebview = [[[UIWebView alloc] init] autorelease];

        [self.view addSubview:_callWebview];

    }

    return [[_callWebview retain] autorelease];

}

- (void)didClickCallButtonAtIndexPath:(NSIndexPath *)indexPath{

AddressPerson *person = self.addressBook[self.orderedKeys[indexPath.section]][indexPath.row];

NSString *telUrl = [NSString stringWithFormat:@"tel:%@",person.phoneNumber];

    NSURL *telURL =[NSURL URLWithString:telUrl];

[self.callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];

}

- (void)dealloc{

    RELEASE_SAFE(_callWebview);

    [super dealloc];

}


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

- (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]];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值