大家想不想在自己的应用中拨打电话呀?打电话可以用openURL:这个API, 如:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];但是当电话结束后,返回的是系统的拨打电话界面,如何才能返回自己的应用呢?这儿有两种方法与大家分享。
第一种是用UIWebView加载电话,这种是合法的,可以上App Store的。
代码如下:
- //assumingyouhaveanivartostoreaweakreferencetoaUIWebView:
- //UIWebView*phoneCallWebView;
- -(void)dialPhoneNumber:(NSString*)aPhoneNumber
- {
- NSURL*phoneURL=[NSURLURLWithString:[NSStringstringWithFormat:@"tel:%@",aPhoneNumber]];
- if(!phoneCallWebView){
- phoneCallWebView=[[UIWebViewalloc]initWithFrame:CGRectZero];
- }
- [phoneCallWebViewloadRequest:[NSURLRequestrequestWithURL:phoneURL]];
- }
- -(void)dealloc
- {
- //cleanup
- [phoneCallWebViewrelease],phoneCallWebView=nil;
- [superdealloc];
- }
第二种是私有方法,不能上App Store的。
- [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"telprompt://10086"]];
大家想不想在自己的应用中拨打电话呀?打电话可以用openURL:这个API, 如:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];但是当电话结束后,返回的是系统的拨打电话界面,如何才能返回自己的应用呢?这儿有两种方法与大家分享。
第一种是用UIWebView加载电话,这种是合法的,可以上App Store的。
代码如下:
- //assumingyouhaveanivartostoreaweakreferencetoaUIWebView:
- //UIWebView*phoneCallWebView;
- -(void)dialPhoneNumber:(NSString*)aPhoneNumber
- {
- NSURL*phoneURL=[NSURLURLWithString:[NSStringstringWithFormat:@"tel:%@",aPhoneNumber]];
- if(!phoneCallWebView){
- phoneCallWebView=[[UIWebViewalloc]initWithFrame:CGRectZero];
- }
- [phoneCallWebViewloadRequest:[NSURLRequestrequestWithURL:phoneURL]];
- }
- -(void)dealloc
- {
- //cleanup
- [phoneCallWebViewrelease],phoneCallWebView=nil;
- [superdealloc];
- }
第二种是私有方法,不能上App Store的。
- [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"telprompt://10086"]];
本文分享了两种在iOS应用中拨打电话的方法:一种是通过UIWebView加载电话,符合AppStore规定;另一种是使用私有方法,无法上架AppStore。文章提供了具体的实现代码。
121

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



