Call the official *Settings* app from my app on iPhone

后端 未结 9 849
名媛妹妹
名媛妹妹 2020-11-28 23:51

At one point in my app, I would like to redirect the user to the official Settings app. If possible, I also want go straight to the Network section within

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 00:25

    Calling the settings app from other app is possible only from iOS 8. So, use the following code

    if([CLLocationManager locationServicesEnabled]&&
       [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
    {
      //...Location service is enabled
    }
    else
    {
        if([[[UIDevice currentDevice] systemVersion] floatValue]<8.0)
        {
          UIAlertView* curr1=[[UIAlertView alloc] initWithTitle:@"This app does not have access to Location service" message:@"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
          [curr1 show];
        }
        else
        {
           UIAlertView* curr2=[[UIAlertView alloc] initWithTitle:@"This app does not have access to Location service" message:@"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Settings", nil];
           curr2.tag=121;
           [curr2 show];
        }
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
       if (alertView.tag == 121 && buttonIndex == 1)
     {
      //code for opening settings app in iOS 8
       [[UIApplication sharedApplication] openURL:[NSURL  URLWithString:UIApplicationOpenSettingsURLString]];
     }
    }
    

提交回复
热议问题