iOS开发------跳转至当前Application Setting界面

来源:互联网 发布:java 注解中value值 编辑:程序博客网 时间:2024/06/02 06:00

最近回归公司项目的时候,感觉目前定位时用户体验稍差,稍作考虑,还是决定参考一下高德地图的用法。

在使用高德地图的时候,如果我们故意的将定位权限关闭,那么在使用它进行定位的时候,它会给我们一个友好提示,当点击设置的时候就会跳到当前App的设置界面,不仅增强了用户的体验而且提高了代码的健壮性,图例如下:


由于多个控制器都会用到此方法,所以决定在基类中实现如下类目:

//实现控制器基类的一个类目@implementation BaseViewController (CLLocationManager)- (void)checkLocationStatus:(void (^)(void))authorizedBlock{    //对定位权限进行判定    switch ([CLLocationManager authorizationStatus])    {        //表示定位允许        case kCLAuthorizationStatusAuthorizedWhenInUse:        case kCLAuthorizationStatusAuthorizedAlways:        {            //执行回调            authorizedBlock();        }             break;        //表示定位不允许,需要弹出Alert        case kCLAuthorizationStatusDenied:        case kCLAuthorizationStatusRestricted:        {            UIAlertView * signAlertView = [[UIAlertView alloc]initWithTitle:@"请打开系统设置中“隐私→定位服务”,允许“XX”使用您的位置。"                                                                    message:nil                                                                   delegate:self                                                          cancelButtonTitle:nil                                                          otherButtonTitles:@"取消",@"设置", nil];            [signAlertView show];        }            break;        default:            break;    }}


实现当前AlertView的Delegate(因为项目适配iOS7,所以懒得用UIAlertController了0.0)

#pragma mark - *************** <UIAlertViewDelegate>//实现UIAlertViewDelegate方法-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    if (buttonIndex == 1)//点击设置    {#ifdef __IPHONE_8_0        //跳入当前App设置界面,因为URLWithString:UIApplicationOpenSettingsURLString是iOS8之后新增的        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];#else        //适配iOS7 ,跳入系统设置界面        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"prefs:General&path=Reset"]];#endif    }}


为了适配一下iOS8之前的操作,还需在Target->Info->URL Types中添加一个字段,如下:



下面是跳转至其他的设置界面的URL:
更加详细内容请参考博文App跳转至系统Settings

Notification — prefs:root=NOTIFICATI_IDPhone — prefs:root=PhonePhotos — prefs:root=PhotosProfile — prefs:root=General&path=ManagedConfigurationListReset — prefs:root=General&path=ResetSafari — prefs:root=SafariSiri — prefs:root=General&path=AssistantSounds — prefs:root=SoundsSoftware Update — prefs:root=General&path=SOFTWARE_UPDATE_LINKStore — prefs:root=STORETwitter — prefs:root=TWITTERUsage — prefs:root=General&path=USAGEVPN — prefs:root=General&path=Network/VPNWallpaper — prefs:root=WallpaperWi-Fi — prefs:root=WIFI

———-更新 2016-10-19————

iOS10之后的路径似乎发生了许变化,如下(摘自cyanzhong/app-tutorials/schemes.md):

电池电量 Prefs:root=BATTERY_USAGE通用设置 Prefs:root=General存储空间 Prefs:root=General&path=STORAGE_ICLOUD_USAGE/DEVICE_STORAGE蜂窝数据 Prefs:root=MOBILE_DATA_SETTINGS_IDWi-Fi 设置 Prefs:root=WIFI蓝牙设置 Prefs:root=Bluetooth定位设置 Prefs:root=Privacy&path=LOCATION辅助功能 Prefs:root=General&path=ACCESSIBILITY关于手机 Prefs:root=General&path=About键盘设置 Prefs:root=General&path=Keyboard显示设置 Prefs:root=DISPLAY声音设置 Prefs:root=SoundsApp Store 设置 Prefs:root=STORE墙纸设置 Prefs:root=Wallpaper打开电话 Mobilephone://世界时钟 Clock-worldclock://闹钟 Clock-alarm://秒表 Clock-stopwatch://倒计时 Clock-timer://打开相册 Photos://


最后祝大家节日快乐啊O(∩_∩)O

0 0
原创粉丝点击