1. 程式人生 > >iOS 跳轉至系統設定頁面整理以及繞過稽核的跳轉方法

iOS 跳轉至系統設定頁面整理以及繞過稽核的跳轉方法

示例:專案裡面有掃碼功能,當用戶第一次掃碼—選擇不允許訪問相機,再次使用掃碼APP就需要引導使用者到系統的相機頁面開啟相機許可權。類似的功能還有定位、錄音、藍芽、相簿等,這些功能都需要給使用者提示/引導。

根據上述情況,市場上的App有兩種做法:

  • 不做跳轉,給使用者提示;
  • 給使用者提示,並做跳轉,引導使用者到設定介面; 

 

總述:

iOS10之前可以進入系統設定的子頁面
iOS11之後不允許跳轉到設定的子頁面,只允許跳轉到設定介面(首頁)

 
// 跳轉到設定 - 相機 / 該應用的設定介面
NSURL *url1 = [NSURL URLWithString:@"App-Prefs:root=Privacy&path=CAMERA"];
// iOS10也可以使用url2訪問,不過使用url1更好一些,可具體根據業務需求自行選擇
NSURL *url2 = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if (@available(iOS 11.0, *)) {
    if ([[UIApplication sharedApplication] canOpenURL:url2]){
        [[UIApplication sharedApplication] openURL:url2 options:@{} completionHandler:nil];
    }
} else {
    if ([[UIApplication sharedApplication] canOpenURL:url1]){
        if (@available(iOS 10.0, *)) {
            [[UIApplication sharedApplication] openURL:url1 options:@{} completionHandler:nil];
        } else {
            [[UIApplication sharedApplication] openURL:url1];
        }
    }
}

附:iOS 10之前常用的跳轉指令(現已經被蘋果列為非公開API,有稽核風險) 

  • iOS 10 以前:
蜂窩網路:prefs:root=MOBILE_DATA_SETTINGS_ID
Wi-Fi:prefs:root=WIFI
定位服務:prefs:root=LOCATION_SERVICES
個人熱點:prefs:root=INTERNET_TETHERING
關於本機:prefs:root=General&path=About
輔助功能:prefs:root=General&path=ACCESSIBILITY
飛航模式:prefs:root=AIRPLANE_MODE
鎖定:prefs:root=General&path=AUTOLOCK
亮度:prefs:root=Brightness
藍芽:prefs:root=Bluetooth
時間設定:prefs:root=General&path=DATE_AND_TIME
FaceTime:prefs:root=FACETIME
設定:prefs:root=General
設定 prefs:root=SETTING
定位服務 prefs:root=LOCATION_SERVICES
鍵盤設定:prefs:root=General&path=Keyboard
iCloud:prefs:root=CASTLE
iCloud備份:prefs:root=CASTLE&path=STORAGE_AND_BACKUP
語言:prefs:root=General&path=INTERNATIONAL
定位:prefs:root=LOCATION_SERVICES
音樂:prefs:root=MUSIC
  • iOS 10 開始
Wi-Fi: App-Prefs:root=WIFI
藍芽: App-Prefs:root=Bluetooth
蜂窩行動網路: App-Prefs:root=MOBILE_DATA_SETTINGS_ID
個人熱點: App-Prefs:root=INTERNET_TETHERING
運營商: App-Prefs:root=Carrier
通知: App-Prefs:root=NOTIFICATIONS_ID
通用: App-Prefs:root=General
通用-關於本機: App-Prefs:root=General&path=About
通用-鍵盤: App-Prefs:root=General&path=Keyboard
通用-輔助功能: App-Prefs:root=General&path=ACCESSIBILITY
通用-語言與地區: App-Prefs:root=General&path=INTERNATIONAL
通用-還原: App-Prefs:root=Reset
牆紙: App-Prefs:root=Wallpaper
Siri: App-Prefs:root=SIRI
隱私: App-Prefs:root=Privacy
定位: App-Prefs:root=LOCATION_SERVICES
Safari: App-Prefs:root=SAFARI
音樂: App-Prefs:root=MUSIC
音樂-均衡器: App-Prefs:root=MUSIC&path=com.apple.Music:EQ
照片與相機: App-Prefs:root=Photos
FaceTime: App-Prefs:root=FACETIME

iOS 10 繞過稽核進行跳轉到藍芽開關的方法

//親測iOS 10.3.3 有效
- (void)turnToBluetooth {
     if (iOS_Version <= 10) {
         [self setBlueTooth];
    } else {//@"App-Prefs:root=General&path=Bluetooth"
        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        [[UIApplication sharedApplication] openURL:url];
    }
}


-(NSString *) getDefaultWork{
    NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x57,0x6f,0x72,0x6b,0x73,0x70,0x61,0x63,0x65} length:16];
    NSString *method = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];
    return method;
}

-(NSString *) getBluetoothMethod{
    NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x6f, 0x70, 0x65, 0x6e, 0x53, 0x65, 0x6e, 0x73, 0x69,0x74, 0x69,0x76,0x65,0x55,0x52,0x4c} length:16];
    NSString *keyone = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];
    NSData *dataTwo = [NSData dataWithBytes:(unsigned char []){0x77,0x69,0x74,0x68,0x4f,0x70,0x74,0x69,0x6f,0x6e,0x73} length:11];
    NSString *keytwo = [[NSString alloc] initWithData:dataTwo encoding:NSASCIIStringEncoding];
    NSString *method = [NSString stringWithFormat:@"%@%@%@%@",keyone,@":",keytwo,@":"];
    return method;
}

-(void)setBlueTooth {
    NSString * defaultWork = [self getDefaultWork];
    NSString * bluetoothMethod = [self getBluetoothMethod];
    NSURL*url=[NSURL URLWithString:@"Prefs:root=Bluetooth"];
    Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
    [[LSApplicationWorkspace performSelector:NSSelectorFromString(defaultWork)] performSelector:NSSelectorFromString(bluetoothMethod) withObject:url withObject:nil];

}

參考原文連結:https://www.jianshu.com/p/be09f5709c2c

參考原文連結:https://www.jianshu.com/p/5fd0ac245e85