UIAlertView like “Turn On Location Services to all

2019-01-17 17:09发布

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

7条回答
Luminary・发光体
2楼-- · 2019-01-17 17:48

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];
      }
  }
查看更多
小情绪 Triste *
3楼-- · 2019-01-17 17:48

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.

查看更多
放荡不羁爱自由
4楼-- · 2019-01-17 17:50

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

查看更多
Deceive 欺骗
5楼-- · 2019-01-17 17:55

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

查看更多
We Are One
6楼-- · 2019-01-17 17:57

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.

查看更多
我只想做你的唯一
7楼-- · 2019-01-17 18:09

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)
}
查看更多
登录 后发表回答