在我們做打電話這個功能時,我們常常是調用這個方法:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://xxxxx"]];
然而,這樣實現了功能後,結束通話後,確不能回到自己的應用中來。最近在網上搜了很多,蘋果自己是沒有提供回調函數的。強大的網友們通過用UIWebView這個控件實現了這個方法。
代碼如下:
- (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];
}
還有一種不能上傳到appstore上的方法。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://xxxx"]];
大家可以嘗試下。