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
 
 

猜你喜欢

转载自blog.csdn.net/sinat_32283541/article/details/86138988
今日推荐