我想拥有与 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/