大家想不想在自己的應用中撥打電話呀?打電話可以用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的。
看到了嗎,其實就是改tel爲telprompt.