IOSTips:AlertView弹出到系统设置

296 查看

这是IOS8之后的一个新特性:即可以直接在应用内,跳转到应用的setting设置中,然后进行相应的操作!

eg:判断是否开启定位服务而言,如果没开启,则弹出alertview,跳转到设置中,代码如下:

cif([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0){
            UIAlertView *tipMessage = [[UIAlertView alloc] initWithTitle:@"定位服务已关闭" message:kCLMessage_AppDenied delegate:self cancelButtonTitle:nil otherButtonTitles:@"知道了", nil];
            tipMessage.tag = 1001;
            [tipMessage show];
        }else{
            UIAlertView *tipSettingMessage=[[UIAlertView alloc] initWithTitle:@"定位服务已关闭" message:kCLMessage_AppDenied delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
            tipSettingMessage.tag=1002;
            [tipSettingMessage show];
        }
c- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  {
    if (alertView.tag == 1002 && buttonIndex == 1){
        //code for opening settings app in iOS 8
        [[UIApplication sharedApplication] openURL:[NSURL  URLWithString:UIApplicationOpenSettingsURLString]];
    }
}