您的位置:首页 > 移动开发 > IOS开发

IOS 调用拨打电话

2014-07-09 09:18 225 查看
http://blog.csdn.net/favormm/article/details/6034952

原链接

大家想不想在自己的应用中拨打电话呀?打电话可以用openURL:这个API, 如:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];但是当电话结束后,返回的是系统的拨打电话界面,如何才能返回自己的应用呢?这儿有两种方法与大家分享。

第一种是用UIWebView加载电话,这种是合法的,可以上App Store的。

代码如下:

// assuming you have an ivar to store a weak reference to a UIWebView:

// UIWebView *phoneCallWebView;

- (void) dialPhoneNumber:(NSString *)aPhoneNumber

{

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

if ( !phoneCallWebView ) {

phoneCallWebView = [[UIWebView alloc] initWithFrame:CGRectZero];

}

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

}

- (void) dealloc

{

// cleanup

[phoneCallWebView release], phoneCallWebView = nil;

[super dealloc];

}

第二种是私有方法,不能上App Store的。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://10086"]];

看到了吗,其实就是改tel为telprompt.

这样,当电话结束手就可以返回到自己的应用程序。是不是很爽呢?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐