UIAlertView 就像“打开定位服务以允许地图确定您的位置”。设置 +取消

发布于 2024-09-24 14:13:41 字数 230 浏览 2 评论 0原文

我想发出此警报:

Turn On Location Services to allow maps to determine your location

我需要“设置”和“取消”,就像“地图”应用程序一样。

“设置”应该打开设置->常规->位置服务

我没有找到打开设置页面的方法。

你能帮助我吗?

谢谢

I Want to emit this alert:

Turn On Location Services to allow maps to determine your location

I need both "Settings" and "Cancel" exactly like the "maps" application.

"Settings" should open settings->general->location services

I didn't find the way to open the settings page.

Can you help me?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

瀟灑尐姊 2024-10-01 14:13:41

创建警报非常简单,它只是一个(假)模态 UIView。

但是,不可能以编程方式打开“设置”应用,至少在不使用私有方法的情况下会阻止您的应用获得 App Store 批准。

Creating the alert is pretty straightforward, it's just a (faux-)modal UIView.

However, it's not possible to open the Settings app programmatically, at least not without using private methods that will prevent your app from being approved for the App Store.

独自←快乐 2024-10-01 14:13:41

这是你自己不可能完成的。但是,如果您的应用程序需要访问位置服务,操作系统将为您显示一个类似的对话框,如下所示。

编辑:布兰特在下面提到“可以通过在 CLLocationManager 上设置目的属性的值来自定义消息。”

替代文字

This is not possible to accomplish on your own. However, if your application needs to access location services the OS will present a dialog like this for you as seen below.

Edit: Brant mentioned below that "the message can be customized by setting the value of the purpose property on your CLLocationManager."

alt text

川水往事 2024-10-01 14:13:41

您无法打开“常规”、“位置”等特定设置页面,但可以在 iOS 8 中打开设置页面。

  - (void)openSettings
  {
      BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
      if (canOpenSettings)
      {
          NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
          [[UIApplication sharedApplication] openURL:url];
      }
  }

You can't open specific settings page like General, Locatios etc., but you can open settings page in iOS 8.

  - (void)openSettings
  {
      BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
      if (canOpenSettings)
      {
          NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
          [[UIApplication sharedApplication] openURL:url];
      }
  }
在风中等你 2024-10-01 14:13:41

斯威夫特2.0版本:

func showLocationSettingAlert() {
    let alertController = UIAlertController(
        title:  "Location Access Disabled",
        message: "Location settings",
        preferredStyle: .Alert)

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
    alertController.addAction(cancelAction)

    let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in
        if let url = NSURL(string:UIApplicationOpenSettingsURLString) {
            UIApplication.sharedApplication().openURL(url)
        }
    }
    alertController.addAction(openAction)
    self.presentViewController(alertController, animated: true, completion: nil)
}

Swift 2.0 version:

func showLocationSettingAlert() {
    let alertController = UIAlertController(
        title:  "Location Access Disabled",
        message: "Location settings",
        preferredStyle: .Alert)

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
    alertController.addAction(cancelAction)

    let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in
        if let url = NSURL(string:UIApplicationOpenSettingsURLString) {
            UIApplication.sharedApplication().openURL(url)
        }
    }
    alertController.addAction(openAction)
    self.presentViewController(alertController, animated: true, completion: nil)
}
落日海湾 2024-10-01 14:13:41

目前无法以编程方式打开设置窗格。请参阅此处

It's not possible to open the setting pane programmatically at this moment. Refer to here.

云淡月浅 2024-10-01 14:13:41

这不是你添加的东西。当应用程序想要使用位置服务但它在设置中关闭时,该屏幕就会出现。

推送通知也会发生同样的情况。

It's not something you add. That screen comes up when the applications wants to use locational services but it's turned off in the settings.

The same thing happens with push notifications.

乖不如嘢 2024-10-01 14:13:41

换句话说,如果您希望应用程序出现在 App Store 上,则无法以编程方式打开“设置”应用程序。
如果您的应用程序支持并使用定位服务等确定的功能,则此弹出窗口会在您的应用程序启动时自动“生成”。
您可以在参考库中找到有关此服务的更多信息:https ://developer.apple.com/library/ios/navigation/#section=Frameworks&topic=CoreLocation

How other said, you can't open Settings app programmatically if you want your app on the App Store.
This popup is automatically "generated" at launch of your app if it support and uses a determined functions like Location Service.
You can find more informations about this service on the Reference Library: https://developer.apple.com/library/ios/navigation/#section=Frameworks&topic=CoreLocation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文