【问题标题】:is it possible to open Settings App using openURL?是否可以使用 openURL 打开设置应用程序?
【发布时间】:2010-11-08 14:08:30
【问题描述】:

我知道一个应用可以使用以下代码启动其他应用:[[UIApplication sharedApplication] openURL:appUrl];。而且我知道打开 safari 和邮件的 URL 方案,但是我做了一些搜索,没有发现关于 settings.app 的方案。

【问题讨论】:

标签: iphone settings


【解决方案1】:

Swift 4 版本:

if let url = URL(string: UIApplicationOpenSettingsURLString) {
    UIApplication.shared.openURL(url)
}

【讨论】:

    【解决方案2】:

    您可以在 iOS 版本 5.0 - 5.0.1 中使用它。然后它在 iOS 5.1 中被弃用。

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
    

    【讨论】:

      【解决方案3】:

      只能从 iOS 8 以编程方式打开设置应用程序。因此,请使用来自http://code-ios.blogspot.in/2014/10/opening-settings-app-from-another-app.html 的以下代码

      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
      {
       NSLog(@"buttonIndex:%d",buttonIndex);
      
         if (alertView.tag == 121 && buttonIndex == 1)
       {
        //code for opening settings app in iOS 8
         [[UIApplication sharedApplication] openURL:[NSURL  URLWithString:UIApplicationOpenSettingsURLString]];
       }
      }
      

      【讨论】:

      • 虽然用户对它没有太多控制权,但您可能需要添加一个检查 [CLLocationManager authorizationStatus] != kCLAuthorizationStatusRestricted
      【解决方案4】:

      您可以以编程方式打开设置应用程序试试这个(仅适用于 iOS8 及以上)。

      如果您使用的是 Swift:

          UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString))
      

      如果你使用的是 Objective-C

         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
      

      对于其他较低版本(低于 iOS8),无法以编程方式打开设置应用程序。

      【讨论】:

      • 竖起大拇指!这很棒。我在 iOS 7.1 上进行了测试,结果应用程序崩溃了,果然,在运行 iOS 8 时,它会将您带到 Apple 设置
      • 有没有办法打开常规设置应用程序(顶级),而不是深入到您自己的应用程序设置?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 2011-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-17
      相关资源
      最近更新 更多