Xcode iOS 打電話功能
方法一
1.這種方法,網上很多說法是,撥打完,電話。回不到原來的應用,會停留在通訊錄裡,而且是直接撥打,不彈出提示
但本人在iOS 10.3測試是,有 提示框的。也會回到原來的應用。其他版本系統沒有測試過。
喚起提示框,很略慢。
NSString *telephoneNumber=@"撥打的號碼";
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",telephoneNumber];
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:str];
[application openURL:URL];
方法二
這種方法,打完電話後還會回到原來的程序,也會彈出提示
但本人在iOS 10.3測試,喚起提示框,很略慢。
NSString *telephoneNumber=@"撥打的號碼";
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",telephoneNumber];
UIWebView * callWebview = [[UIWebView alloc] init];
[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
[self.view addSubview:callWebview];
[callWebview release];
[str release];
方法三
這種方法也會回去到原來的程序裡(注意這裡的telprompt),也會彈出提示
但本人在iOS 10.3測試,喚起提示框,很略慢。
NSString *telephoneNumber=@"撥打的號碼";
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",telephoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]
方法四
打完電話後還會回到原來的程序,也會彈出提示
前面的三種方法都會有⚠️,提示ios10後不再推薦使用。
官方,iOS 10之後推薦使用下面的方法
但本人在iOS 10.3測試,喚起提示框,比前面三種方法快。
NSString *telephoneNumber=@"撥打的號碼";
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",telephoneNumber];
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:str];
[application openURL:URL options:@{} completionHandler:^(BOOL success) {
//OpenSuccess=選擇 呼叫 為 1 選擇 取消 為0
NSLog(@"OpenSuccess=%d",success);
}];
留言
張貼留言