在iOS开发过程中,有时我们想在应用内实现打电话、发短信、打开Safari浏览器功能,具体常用功能如下:
if ([[UIapplication sharedApplication] openURL:[NSURL URLWithString:@"tel://185XXXX0496"]]){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://185XXXX0496"]];}调用打电话功能(此种方法会询问是否拨打电话,电话结束后会返回到应用界面,但是有上架App Store被拒的案例)if ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telPRompt://185XXXX0496"]]){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://185XXXX0496"]];}调用打电话功能(此种方法会询问是否拨打电话,电话结束后会返回到应用界面,此种方法是加载了一个UIWebView实现,支持上架App Store)UIWebView *webView = [[UIWebView alloc] init];[webView loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:@"tel://185XXXX0496"]]];[self.view addSubview:webView];调用发短信功能(此种方法会直接跳转到给指定号码发送短信,短信结束后会留在短信界面)
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://www.baidu.com/"]]){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu.com/"]];}iOS跳转到系统设置
在iOS开发过程中,有时我们想在应用内实现跳转到系统设置界面,具体常用功能如下:
注意:想要实现应用内跳转到系统设置界面功能,需要先在 Targets
- Info
- URL Types
-URL Schemes
中添加 prefs
跳转到WIFI设置
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs:root=WIFI"]]){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];}跳转到蓝牙
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]]){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]];}跳转到通用
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs:root=General"]]){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General"]];}跳转到关于本机
if ([[UIApplication sharedApplication] canOpenURL:[NSURLURLWithString: @"prefs:root=General&path=About"]]){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs: root=General&path=About"]];}跳转到定位服务
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs: root=LOCATION_SERVICES"]]){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs: root=LOCATION_SERVICES"]];}跳转到通知
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs: root=NOTIFICATIONS_ID"]]){ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs: root=NOTIFICATIONS_ID"]];}
新闻热点
疑难解答