应用内跳转到设置页面

针对iOS10不跳转问题,其实iOS提供了一套未公开方法。但审核是一个问题,不过我们可以想办法绕过审核。

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];

利用ASCII值进行拼装组合方法。这样可绕过审核。

-(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;
}

上面是进入蓝牙界面的方法。也可以有其他的页面可以跳转。设置页面是@"@"Prefs:root=TETHERING",wifi是@"Prefs:root=WIFI"。注意Prefs的P是大写。这么写也有弊端,如果苹果的未公开方法一旦修改。我们必须重新进行修改。

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

直接点击跳转到系统设置界面, 设置通知定位等等

在操作之前, 你需要info中设置 URLTypes, 如下图所示 
演示图

直接通过 root=* 什么来配置

NSArray *dataArray = @[

               @{@"系统设置":@"prefs:root=INTERNET_TETHERING"},

               @{@"WIFI设置":@"prefs:root=WIFI"},

               @{@"蓝牙设置":@"prefs:root=Bluetooth"},

               @{@"系统通知":@"prefs:root=NOTIFICATIONS_ID"},

               @{@"通用设置":@"prefs:root=General"},

               @{@"显示设置":@"prefs:root=DISPLAY&BRIGHTNESS"},

               @{@"壁纸设置":@"prefs:root=Wallpaper"},

               @{@"声音设置":@"prefs:root=Sounds"},

               @{@"隐私设置":@"prefs:root=privacy"},

               @{@"APP Store":@"prefs:root=STORE"},

               @{@"Notes":@"prefs:root=NOTES"},

               @{@"Safari":@"prefs:root=Safari"},

               @{@"Music":@"prefs:root=MUSIC"},

               @{@"photo":@"prefs:root=Photos"}

               ];
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

如果要跳转本应用的设置界面中,使用prefs:root=boundleId的方式,bundled是应用的bundled

像这样, 我直接调到本应用的通知设置界面

{@"应用通知":@"prefs:root=NOTIFICATIONS_ID&path=boundleId"}
  
  
  • 1
  • 1

通过添加path路径的方式进行

NSArray *dataArray0 = @[

                            @{@"关于本机":@"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"}
                            ];
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

之后使用openURL方法

NSURL *url = [NSURL URLWithString:[dataArray0[11] objectForKey:@"应用通知"]];
    if ([UIDevice currentDevice].systemVersion.floatValue <= 10.0) {
        [[UIApplication sharedApplication] openURL:url];
    }else{
        // iOS10 之后, 比较特殊, 只能跳转到设置界面 , UIApplicationOpenSettingsURLString这个只支持iOS8之后.
        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
            // 还可以跳过success这个bool值进行更加精确的判断.
            NSLog(@"跳转成功回调");
        }];
    }
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

在iOS10之后还有个值得注意的地方, 如果在跳转设置界面之前, 没有申请某种权限, 跳转之后直接crash 
便于测试你可以先获取一下通知权限.

if ([[[UIDevice currentDevice]systemVersion]floatValue] >= 8) {
        UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
    }
  
  
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

更多参数配置, 可以在应用中加入更多的设置需求.

prefs:root=General&path=About
prefs:root=General&path=ACCESSIBILITY
prefs:root=AIRPLANE_MODE
prefs:root=General&path=AUTOLOCK
prefs:root=General&path=USAGE/CELLULAR_USAGE
prefs:root=Brightness
prefs:root=General&path=Bluetooth
prefs:root=General&path=DATE_AND_TIME
prefs:root=FACETIME
prefs:root=General
prefs:root=General&path=Keyboard
prefs:root=CASTLE
prefs:root=CASTLE&path=STORAGE_AND_BACKUP
prefs:root=General&path=INTERNATIONAL
prefs:root=LOCATION_SERVICES
prefs:root=ACCOUNT_SETTINGS
prefs:root=MUSIC
prefs:root=MUSIC&path=EQ
prefs:root=MUSIC&path=VolumeLimit
prefs:root=General&path=Network
prefs:root=NIKE_PLUS_IPOD
prefs:root=NOTES
prefs:root=NOTIFICATIONS_ID
prefs:root=Phone
prefs:root=Photos
prefs:root=General&path=ManagedConfigurationList
prefs:root=General&path=Reset
prefs:root=Sounds&path=Ringtone
prefs:root=Safari
prefs:root=General&path=Assistant
prefs:root=Sounds
prefs:root=General&path=SOFTWARE_UPDATE_LINK
prefs:root=STORE
prefs:root=TWITTER
prefs:root=General&path=USAGE
prefs:root=VIDEO
prefs:root=General&path=Network/VPN
prefs:root=Wallpaper
prefs:root=WIFI
prefs:root=INTERNET_TETHERING


iOS之访问权限以及跳转到系统界面

iOS开发中有时候有这样的需求:当用户设置不允许访问照片、麦克风和相机等系统权限的时候,这时需要直接跳转到系统的隐私界面进行设置。

判断是否开启权限

前面已经说过,我们需要在用户不允许访问的时候跳转,那么首先我们就要判断一些是否已经开启系统相机权限了。

照片权限检测

需要:#import <AssetsLibrary/AssetsLibrary.h> //导入此类和AssetsLibrary.framework框架

代码如下:

int author = [ALAssetsLibrary authorizationStatus];
            NSLog(@"author type:%d",author);
            if(author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied) {
                // The user has explicitly denied permission for media capture. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"无法使用相册" message:@"请在iPhone的\"设置-隐私-照片\"中允许访问照片。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; return;
ALAssetsLibrary类

ALAssetsLibrary类是代表系统中整个资源库,使用它可以访问资源库中的资源和保存照片,视频等功能。

    //判断当前应用是否能访问相册资源
    /*
     typedef NS_ENUM(NSInteger, ALAuthorizationStatus) {
     ALAuthorizationStatusNotDetermined = 0, 用户尚未做出了选择这个应用程序的问候
     ALAuthorizationStatusRestricted,        此应用程序没有被授权访问的照片数据。可能是家长控制权限。
     ALAuthorizationStatusDenied,            用户已经明确否认了这一照片数据的应用程序访问.
     ALAuthorizationStatusAuthorized         用户已授权应用访问照片数据.
     }
     */

访问摄像头

需要:#import <AVFoundation/AVFoundation.h>

代码如下:

if(isIOS7AndLater) {

NSString *mediaType = AVMediaTypeVideo;// Or AVMediaTypeAudio
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; NSLog(@"---cui--authStatus--------%d",authStatus); // This status is normally not visible—the AVCaptureDevice class methods for discovering devices do not return devices the user is restricted from accessing. if(authStatus ==AVAuthorizationStatusRestricted){ NSLog(@"Restricted"); }else if(authStatus == AVAuthorizationStatusDenied){ // The user has explicitly denied permission for media capture. NSLog(@"Denied"); //应该是这个,如果不允许的话 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请在设备的\"设置-隐私-相机\"中允许访问相机。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; return; } else if(authStatus == AVAuthorizationStatusAuthorized){//允许访问 // The user has explicitly granted permission for media capture, or explicit user permission is not necessary for the media type in question. NSLog(@"Authorized"); }else if(authStatus == AVAuthorizationStatusNotDetermined){ // Explicit user permission is required for media capture, but the user has not yet granted or denied such permission. [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) { if(granted){//点击允许访问时调用 //用户明确许可与否,媒体需要捕获,但用户尚未授予或拒绝许可。 NSLog(@"Granted access to %@", mediaType); } else { NSLog(@"Not granted access to %@", mediaType); } }]; }else { NSLog(@"Unknown authorization status"); } }

麦克风权限检测

代码如下:

  //检测麦克风功能是否打开
    [[AVAudioSessionsharedInstance]requestRecordPermission:^(BOOL granted) {
        if (!granted)
        {
            [ViewUtilalertViewWithString:NSLocalizedString(@"麦克风功能未开启",nil)]; } else { [selfrecord:sender]; } }];

如何跳转到系统设置界面

判断权限是否设置之后就可以在相应的代理方法进行界面跳转了,那么如何进行跳转呢?

首先要在项目中的info.plist中添加 URL types 并设置一项URL Schemes为prefs,如下图:


1.jpg

实现代码如下:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];//url为具体路径
以下是跳转到一些常用界面的代码

隐私->照片界面

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=PHOTOS"]];

隐私->相机界面

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=CAMERA"]];

蓝牙设置界面

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]];

其他界面参数配置

About — prefs:root=General&path=About

Accessibility — prefs:root=General&path=ACCESSIBILITY

Airplane Mode On — prefs:root=AIRPLANE_MODE

Auto-Lock — prefs:root=General&path=AUTOLOCK

Brightness — prefs:root=Brightness

Bluetooth — prefs:root=General&path=Bluetooth

Date & Time — prefs:root=General&path=DATE_AND_TIME

FaceTime — prefs:root=FACETIME

General — prefs:root=General

Keyboard — prefs:root=General&path=Keyboard

iCloud — prefs:root=CASTLE

iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP

International — prefs:root=General&path=INTERNATIONAL

Location Services — prefs:root=LOCATION_SERVICES

Music — 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

// 

@"prefs:root=NOTIFICATIONS_ID&path=应用的boundleId"

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

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

Wallpaper — prefs:root=Wallpaper

Wi-Fi — prefs:root=WIFI







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值