简体   繁体   English

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

[英]UIAlertView like “Turn On Location Services to allow maps to determine your location”. Settings + Cancel

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 谢谢

Creating the alert is pretty straightforward, it's just a (faux-)modal UIView. 创建警报非常简单,它只是一个(仿)模式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. 但是, 无法以编程方式打开“设置”应用,至少在没有使用会阻止您的应用被批准用于App Store的私有方法的情况下。

You can't open specific settings page like General, Locatios etc., but you can open settings page in iOS 8. 您无法打开常规,Locatios等特定设置页面,但您可以在iOS 8中打开设置页面。

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

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." 编辑:下面提到的Brant“可以通过在CLLocationManager上设置目的属性的值来自定义消息。”

替代文字

Swift 2.0 version: Swift 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)
}

It's not possible to open the setting pane programmatically at this moment. 此时无法以编程方式打开设置窗格。 Refer to here . 请参阅此处

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. 推送通知也会发生同样的事情。

How other said, you can't open Settings app programmatically if you want your app on the App Store. 其他人怎么说,如果你想在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 您可以在参考资料库中找到有关此服务的更多信息: https//developer.apple.com/library/ios/navigation/#section=Frameworks&topic=CoreLocation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM