最常見的方式是透過 UIApplication 開啟 tel 開頭的 URL。此方式會由系統接管撥號流程,使用者確認後即可撥打電話。
NSString *phone = @"18749627117"; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phone]]; [[UIApplication sharedApplication] openURL:url];
另一種寫法是使用 telprompt,讓系統先跳出確認提示,撥打後可返回 App。不過此類寫法在不同 iOS 版本與審核政策下可能存在相容性或合規風險,正式專案應謹慎使用。
也可以在 UIWebView 中載入 tel URL,讓系統處理撥號行為。這種方式較舊,但在某些舊專案中仍能看到。
UIWebView *callWebView = [[UIWebView alloc] init]; [callWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:18749627117"]]]; [self.view addSubview:callWebView];
實際開發時,應先確認號碼格式、是否需要在模擬器與實機上測試,以及 App 是否有權限開啟外部 URL。若需要記錄撥號行為,也應在送出請求前完成狀態保存。