1. 程式人生 > >iOS開發- 撥打電話總結

iOS開發- 撥打電話總結

關於iOS應用撥打電話, 我所知道的有3種辦法, 具體如下:

一。利用openURL(tel)

特點: 直接撥打, 不彈出提示。 並且, 撥打完以後, 留在通訊錄中, 不返回到原來的應用。

//撥打電話
- (void)callPhone:(NSString *)phoneNumber
{
    //phoneNumber = "18369......"
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",phoneNumber];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

二。利用requestWithURL (推薦使用)

特點: 撥打前彈出提示。 並且, 撥打完以後會回到原來的應用。

//撥打電話
- (void)callPhone:(NSString *)phoneNumber
{
    //phoneNumber = "18369......"
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",phoneNumber];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
}

三。利用openURL(telprompt)

特點: 撥打前彈出提示。 並且, 撥打完以後會回到原來的應用。

注意: Apple的官方文件中, 沒有出現過telprompt, 之前也有人使用這個, 上傳稽核的時候被拒絕了。

//撥打電話
- (void)callPhone:(NSString *)phoneNumber
{
    //phoneNumber = "18369......"
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",phoneNumber];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}