我們在開發APP 的過程中會經常遇到這樣的需求,跳轉到客服QQ界面,撥打電話等,直接上代碼
1.關于APP跳轉到客服QQ界面
// 空白的webview
UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectZero];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
//1691838426 是QQ號
NSString * string = @"mqq://im/chat?chat_type=wpa&uin=1691838426&version=1&src_type=web";
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"shipping要打開你的QQ" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *callAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:string]]];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[actionSheet addAction:cancelAction];
[actionSheet addAction:callAction];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:actionSheet animated:YES completion:nil];
[[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:webView];
}else{
UIAlertView*ale=[[UIAlertView alloc] initWithTitle:@"提示" message:@"您沒有安裝手機QQ,請安裝手機QQ后重試,或用PC進行操作。" delegate:self cancelButtonTitle:nil otherButtonTitles:@"確定", nil];
[ale show];
}
2.關于APP直接撥打電話又三種實現方式
-
第一種:直接撥打電話,沒有提示
//撥打電話
UIApplication *ac = [UIApplication sharedApplication];NSURL *url = [NSURL URLWithString:[@"tel://" stringByAppendingString:@"你要放的電話號碼"]]; [ac openURL:url];
第二種:打完電話后還會回到原來的程序,也會彈出提示,
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"你要放的電話號碼"];
UIWebView * callWebview = [[UIWebView alloc] init];
[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
[self.view addSubview:callWebview];第三種: 打完電話后還會回到原來的程序,也會彈出提示,
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"你要放的電話號碼"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];