iphone - 如何再次提示用户打开定位服务...

标签 iphone ios cllocationmanager

我想拥有与 map 应用程序相同的功能,用户每次按下“当前位置”按钮时都会收到提示以打开他们的位置服务(如果它们处于关闭状态):

  • 关闭定位服务
  • 用户按下“getCurrentLocation”按钮
  • 应用尝试使用 CLLocationManager 获取位置信息
  • 用户收到“打开位置服务...”消息,其中显示“设置”和“取消”按钮。
  • 用户点击“取消”
  • 用户再次按下“getCurrentLocation”按钮
  • 应用再次尝试使用 CLLocationManager 获取位置信息
  • 用户不会再收到“打开定位服务...”消息

在 map 应用程序中,用户每次都会收到“打开位置服务...”消息。我怎样才能让我的应用程序做同样的事情?我让用户使用 CLLocationManager 的新实例,以防出现问题,但事实并非如此。我看不到任何会对此产生影响的设置。

如果我自己制作警报,我将无法获得相同的“设置”按钮功能。此外,我不希望用户看到多个看起来相同的警报。

有什么想法吗?

最佳答案

在 iOS 8 中有一个名为 UIApplicationOpenSettingsURLString 的新常量。

来自"What's new in iOS" UIKit 下的文档是一行:

You can take the user directly to your app-related settings in the Settings app. Pass the UIApplicationOpenSettingsURLString constant to the openURL: method of the UIApplication class.

来自 Apple 的 documentation :

UIApplicationOpenSettingsURLString

Used to create a URL that you can pass to the openURL: method. When you open the URL built from this string, the system launches the Settings app and displays the app’s custom settings, if it has any.

您可以将其传递给 UIApplication openURL: 方法。它可能看起来像:

NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

if ([[UIApplication sharedApplication] canOpenURL:settings])
    [[UIApplication sharedApplication] openURL:settings];

关于iphone - 如何再次提示用户打开定位服务...,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5998465/

相关文章:

ios - UITableView 不显示在模拟器中

iOS UIScrollView/UIView 以双倍大小显示更新的内容

swift - "Delegate must respond to locationManager:didUpdateLocations:"当应用程序处理它时抛出错误

ios - CLLocationManager requestWhenInUseAuthorization错误,没有已知的类方法

iphone - UITableView scrollIndicator 位置不正确

iphone - HTTP POST JSON 方法

iphone - 如何修改我的代码以允许用户将 UIImage 定位在 UIImageView 上?

ios - 在 iOS 上,当我们从上下文中创建一个层并获取层的上下文后,这些上下文如何相互关联?

ios - 使用 UIAlertController 进行错误处理

ios - iOS 8.1 中未调用 didUpdateUserLocation