iOS Developer - TipsiOS开发系列我的ios进阶

iOS调用系统功能与跳转到系统设置

2016-02-25  本文已影响2390人  蚊香酱
图片来源于网络

iOS调用系统功能

在iOS开发过程中,有时我们想在应用内实现打电话、发短信、打开Safari浏览器功能,具体常用功能如下:

if ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://185XXXX0496"]])
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://185XXXX0496"]];
}
if ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://185XXXX0496"]])
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt://185XXXX0496"]];
}
UIWebView *webView = [[UIWebView alloc] init];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://185XXXX0496"]]];
[self.view addSubview:webView];
if ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://185XXXX0496"]])
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://185XXXX0496"]];
}
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
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:[NSURL URLWithString:@"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"]];
}
上一篇下一篇

猜你喜欢

热点阅读