iOS关于应用内直接跳转到设置界面的方法

关于5.1以前的版本 如以下方式打开的方式:

 NSURL *url =[NSURL URLWithString:@"prefs:root=General&path=About"];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        
        [[UIApplication sharedApplication]openURL:url];
    }
    else{

        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"tips" message:@"can,t open this url" delegate:self cancelButtonTitle:nil otherButtonTitles:@"sure", nil];
        [alert show];
    }

url即设置内通用-关于的链接 不过现在对于早已过去的5.1系统来说 这早已不能使用了  现在有更好的方法

现在的一切都集成到了系统的控件中去了 比如使用定位功能 发现不能使用 系统自动提示是否去设置页面打开定位功能 以下是部分代码:

- (void)requestLocationServicesAuthorization {
    self.locationManager = [[CLLocationManager alloc] init];
    [self.locationManager setDelegate:self];
    
    /*
     When the application requests to start receiving location updates that is when the user is presented with a consent dialog.
     */
    [self.locationManager startUpdatingLocation];
}

#pragma mark - CLLocationMangerDelegate methods

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    /*
     Handle the failure...
     */
    [self.locationManager stopUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    /*
     Do something with the new location the application just received...
     */
    [self.locationManager stopUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
    /*
     The delegate function will be called when the permission status changes the application should then attempt to handle the change appropriately by changing UI or setting up or tearing down data structures.
     */
    if(status == kCLAuthorizationStatusNotDetermined) {
        
        [self alertViewWithDataClass:nil status:@"未决定"];
    }
    else if(status == kCLAuthorizationStatusRestricted) {
        
        [self alertViewWithDataClass:nil status:@"已拒绝"];
    }
    else if(status == kCLAuthorizationStatusDenied) {
       
        [self alertViewWithDataClass:nil status:@"以否定"];
    }
    else if(status == kCLAuthorizationStatusAuthorized) {
        [self alertViewWithDataClass:nil status:@"已授权"];
    }
}

这里有官方的代码 自己看一下就明白了

https://developer.apple.com/library/ios/samplecode/PrivacyPrompts/Introduction/Intro.html#//apple_ref/doc/uid/DTS40013410-Intro-DontLinkElementID_2


请叫我雷锋

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值