iOS最新跳轉手機設置WIFI定位等界面方法適配iOS11

iOS的“人性化”不言而喻,就是訪問位置,打開WiFi,,,,都需要得到用戶的允許,而有些請款下,用戶暫時不想打開這些,甚至手抖選錯了關閉,這個時候,就需要你去提醒用戶去打開權限,這個時候,你可以像微信一樣提示用戶"設置"-"定位"。。。但是為了更好地用戶體驗,我們還是希望能直接跳轉到設置界面,讓用戶直接進行設置。

//華麗的分割線--------------------------【??】
最新的跳轉方式:【這里以項目中顯示Alert的形式】

  • (BOOL)checkLocationAuthorizationStatus
    {
    if (![CLLocationManager locationServicesEnabled]) { // disable the location for iPhone
    dispatch_async(dispatch_get_main_queue(), ^{
    [self showLocationServiceDisableAlert:YES];
    });

      return NO;
    

    }
    else {
    if (kCLAuthorizationStatusDenied == [CLLocationManager authorizationStatus]) { // disable the location for this app
    dispatch_async(dispatch_get_main_queue(), ^{
    [self showLocationServiceDisableAlert:NO];
    });
    return NO;
    }
    }

    return YES;
    }

  • (void)showLocationServiceDisableAlert:(BOOL)disable
    {
    UIAlertController *ctrl = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"location_alert_title", @"") message:[NSString stringWithFormat:NSLocalizedString(@"location_alert_prompt",@""),AMDeviceAppName] preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *action1 = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel_action", @"") style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:NSLocalizedString(@"sure_action", @"") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    dispatch_async(dispatch_get_main_queue(), ^{
    NSURL *url = nil;
    if (disable) {
    if (IS_IOS_10_OR_LATER) {
    url = [NSURL URLWithString: @"App-Prefs:root=General&path=LOCATION_SERVICES"];
    }
    else{
    url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
    }
    }
    else {
    url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    }
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
    }
    });
    }];
    [ctrl addAction:action1];
    [ctrl addAction:action2];

    [self presentViewController:ctrl animated:YES completion:nil];
    }

//華麗的分割線--------------------------【??】

鑒于這篇文章被很多朋友詢問,因為這個是好早之前的方式了 ,一直很忙沒有更新,現在特此來更新一下最新的跳轉方式 :
方式一:prefs:root=某項服務
方式二:prefs:root=bundleID
方式三: UIApplicationOpenSettingsURLString

本篇針對iOS7、iOS8、iOS9、iOS10,來介紹其中區(qū)別。

一、跳轉方法

當iOS系統(tǒng)版本 < iOS 10.0 時

NSURL *url= [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
if( [[UIApplication sharedApplication]canOpenURL:url] ) {
[[UIApplication sharedApplication]openURL:url];
}

當iOS系統(tǒng)版本 >=iOS 10.0 時

if( [[UIApplication sharedApplication]canOpenURL:url] ) {
[[UIApplication sharedApplication]openURL:url options:@{}completionHandler:^(BOOL success) {
}];
}

二、跳轉到哪里去?(系統(tǒng)的設置,系統(tǒng)中自己應用下面的設置)

方式一:

當 iOS系統(tǒng)版本 <= iOS7時 , 只能跳轉到 系統(tǒng)設置頁面

NSURL *url= [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
跳轉到: 隱私-定位服務。

prefs:root=某項服務

系統(tǒng)設置:prefs:root=INTERNET_TETHERING

WIFI設置:prefs:root=WIFI

藍牙設置:prefs:root=Bluetooth

系統(tǒng)通知:prefs:root=NOTIFICATIONS_ID

通用設置:prefs:root=General

顯示設置:prefs:root=DISPLAY&BRIGHTNESS

壁紙設置:prefs:root=Wallpaper

聲音設置:prefs:root=Sounds

隱私設置:prefs:root=privacy

蜂窩網路:prefs:root=MOBILE_DATA_SETTINGS_ID

音樂:prefs:root=MUSIC

APP Store:prefs:root=STORE

Notes:prefs:root=NOTES

Safari:prefs:root=Safari

Music:prefs:root=MUSIC

photo":prefs:root=Photos

這種跳轉方式,都是跳轉到系統(tǒng)的設置界面。

方式二 :

當 iOS系統(tǒng)版本 >= iOS8 ,支持跳轉到第三方應用的設置界面中
使用prefs:root=bundleID ,bundleID是你第三方應用工程的唯一ID
局限性:只支持iOS8,iOS9系統(tǒng),在iOS10系統(tǒng)上,不會跳轉。

在iOS7系統(tǒng)上,僅僅只是跳轉到設置應用,不推薦使用。

如果需要繼續(xù)向項目內層進行跳轉,可以通過添加path路徑的方式,如下:

關于本機:prefs:root=General&path=About

軟件升級:prefs:root=General&path=SOFTWARE_UPDATE_LINK

日期時間:prefs:root=General&path=DATE_AND_TIME

Accessibility:prefs:root=General&path=ACCESSIBILITY

鍵盤設置:prefs:root=General&path=Keyboard

VPN:prefs:root=General&path=VPN

壁紙設置:@"prefs:root=Wallpaper

聲音設置:prefs:root=Sounds

隱私設置:prefs:root=privacy

APP Store:prefs:root=STORE

還原設置:prefs:root=General&path=Reset

應用通知:prefs:root=NOTIFICATIONS_ID&path=應用的boundleId

定位:prefs:root=LOCATION_SERVICES

蜂窩網絡:prefs:root=MOBILE_DATA_SETTINGS_ID

VPN — prefs:root=General&path=Network/VPN

Wi-Fi:prefs:root=WIFI

定位服務:prefs:root=LOCATION_SERVICES

個人熱點:prefs:root=INTERNET_TETHERING

輔助功能:prefs:root=General&path=ACCESSIBILITY

飛行模式:prefs:root=AIRPLANE_MODE

鎖定:prefs:root=General&path=AUTOLOCK

亮度:prefs:root=Brightness

藍牙:prefs:root=General&path=Bluetooth

時間設置:prefs:root=General&path=DATE_AND_TIME

FaceTime:prefs:root=FACETIME

設置:prefs:root=General

鍵盤設置:prefs:root=General&path=Keyboard

iCloud:prefs:root=CASTLE

iCloud備份:prefs:root=CASTLE&path=STORAGE_AND_BACKUP

語言:prefs:root=General&path=INTERNATIONAL

音樂:prefs:root=MUSIC

Music Equalizer — prefs:root=MUSIC&path=EQ

Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit

Network — prefs:root=General&path=Network

Nike + iPod — prefs:root=NIKE_PLUS_IPOD

Notes — prefs:root=NOTES

Notification — prefs:root=NOTIFICATIONS_ID

Phone — prefs:root=Phone

Photos — prefs:root=Photos

Profile — prefs:root=General&path=ManagedConfigurationList

Reset — prefs:root=General&path=Reset

Safari — prefs:root=Safari

Siri — prefs:root=General&path=Assistant

Sounds — prefs:root=Sounds

Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK

Store — prefs:root=STORE

Twitter — prefs:root=TWITTER

Usage — prefs:root=General&path=USAGE

Wallpaper — prefs:root=Wallpaper

方式三

當 iOS系統(tǒng)版本 >= iOS8,支持跳轉到自己應用設置,不支持跳轉到系統(tǒng)設置

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

UIApplicationOpenSettingsURLString字段,是在iOS8上才提供的,支持iOS8,iOS9,iOS10系統(tǒng),推薦使用。

當iOS系統(tǒng)版本>= iOS10,支持跳轉到自己應用設置,不支持跳轉到系統(tǒng)設置

只認:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

跳轉。

而 prefs:root=bundleID和 prefs:root=服務 都將不起作用。

總結一下:

方式一:prefs:root=某項服務 適用于 小于 iOS10的系統(tǒng);
方式二:prefs:root=bundleID 適用于 大于等于iOS8系統(tǒng),小于iOS10的系統(tǒng)
方式三:UIApplicationOpenSettingsURLString 適用于 大于等于iOS8的系統(tǒng)

Prefs設置方式:[注意大小寫]

3DDD36E3-E8F4-4B3C-BAC2-2D47139C4B73.png
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容