CLLocation再次请求许可

发布于 2024-10-03 22:17:22 字数 131 浏览 0 评论 0原文

目前,我的应用程序仅请求一次使用当前位置的许可。如果用户不允许,则不会再次询问,除非他在常规设置中重置位置警告。我想让用户有机会在应用程序内稍后授予此权限。换句话说,如果他按下某个按钮,对话框应该再次出现。这可能吗?

谢谢你的建议。

Currently my application asks only once for permission to use the current location. If the user doesn't allow, he isn't ask again unless he resets location warning in the general settings. I would like to give the user a chance from within the app to grant this permission later. In other words, the dialog should appear again if he presses a certain button. Is this possible?

Thanks for your advice.

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

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

发布评论

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

评论(2

下壹個目標 2024-10-10 22:17:22

[CLLocationManager locationServicesEnabled] 只是告诉您设备上是否启用了位置服务。

根据文档。

如果结果是 kCLAuthorizationStatusDenied, [CLLocationManagerauthorizationStatus]

将返回其中之一,

typedef enum {
   kCLAuthorizationStatusNotDetermined = 0,
   kCLAuthorizationStatusRestricted,
   kCLAuthorizationStatusDenied,
   kCLAuthorizationStatusAuthorized
} CLAuthorizationStatus;

您可以通过将用户发送到 settings.app 来告诉用户允许使用位置服务

[CLLocationManager locationServicesEnabled] just tells you if the locations services are enable on the device.

according to this document.

[CLLocationManager authorizationStatus]

will return one of these

typedef enum {
   kCLAuthorizationStatusNotDetermined = 0,
   kCLAuthorizationStatusRestricted,
   kCLAuthorizationStatusDenied,
   kCLAuthorizationStatusAuthorized
} CLAuthorizationStatus;

if the result is kCLAuthorizationStatusDenied your could tell the user to allow the usage of the location services by sending him to the settings.app

作妖 2024-10-10 22:17:22

新答案:
现在,在 iOS 8 中,您可以以编程方式打开设备设置应用程序:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];

如果您支持早期的 iO​​S 版本并希望确保可以处理此问题,请执行以下操作:

if (&UIApplicationOpenSettingsURLString != NULL) {
   NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
   [[UIApplication sharedApplication] openURL:url];
}
else {
  //Earlier iOS version
}

旧答案:
据我所知,没有办法强制显示本机弹出窗口(并允许用户跳转到设置页面)。

您可以使用以下方法来确定用户是否允许您的应用使用位置服务:
CLLocationManager:

+(CLAuthorizationStatus)authorizationStatus

您还可以了解位置服务是否在设备级别全局启用:
CL位置管理器:

+(BOOL)locationServicesEnabled

New Answer:
Now in iOS 8 you CAN programatically open the device settings app:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];

If you are supporting earlier iOS versions and want to make sure this can be handled, do this:

if (&UIApplicationOpenSettingsURLString != NULL) {
   NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
   [[UIApplication sharedApplication] openURL:url];
}
else {
  //Earlier iOS version
}

Old Answer:
There is no way I know of to force the native popup to appear (and allow the user to jump to the settings page).

You can use the following method to determine if the user has allowed location services for your app:
CLLocationManager:

+(CLAuthorizationStatus)authorizationStatus

You can also find out if location services are globally enabled at the device level or not, too:
CLLocationManager:

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