IOS iphone中結束電話後返回自己的應用

大家想不想在自己的應用中撥打電話呀?打電話可以用openURL:這個API, 如:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];但是當電話結束後,返回的是系統的撥打電話界面,如何才能返回自己的應用呢?這兒有兩種 方法與大家分享。

第一種是用UIWebView加載電話,這種是合法的,可以上App Store的。

代碼如下:

  1. // assuming you have an ivar to store a weak reference to a UIWebView:  
  2. // UIWebView *phoneCallWebView;  
  3. - (void) dialPhoneNumber:(NSString *)aPhoneNumber  
  4. {  
  5.     NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",aPhoneNumber]];  
  6.     if ( !phoneCallWebView ) {          
  7.         phoneCallWebView = [[UIWebView alloc] initWithFrame:CGRectZero];  
  8.     }  
  9.     [phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];  
  10. }  
  11. - (void) dealloc  
  12. {  
  13.     // cleanup  
  14.     [phoneCallWebView release], phoneCallWebView = nil;  
  15.    [super dealloc];  
  16. }  
 

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


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

   看到了嗎,其實就是改tel爲telprompt.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章