如何在 iPhone xcode 上检测 GPS 的开/关以及我们如何知道我们的应用程序不允许使用 GPS?

发布于 2024-11-26 11:58:52 字数 323 浏览 0 评论 0原文

我想制作将使用 GPS 的应用程序,正如我们所知,用户第一次使用需要 GPS/当前位置的应用程序时,会弹出一个请求许可的窗口,问题是.. 例如:

用户选择不允许,那么我们如何知道用户使我们的应用程序无法访问她/他的 GPS 来了解他/她的位置?因为我的应用程序需要 CurrentLocation,所以如果我可以检测用户选择的内容,我想制作一个像第一个弹出窗口一样的弹出窗口,再次请求许可。

或者任何可以让我的应用程序打开/关闭 GPS 的代码?

想象一下,如果用户错误地不允许?我的应用程序是否可以询问用户?

当位置不可用时,像 Yelp 这样的应用程序应该做什么?

I want to make application that will use GPS, as we know at first time user use our application that need gps/current location, there is a pop up that asking for permission, the problem is.. example:

the user choose not allow, and then how can we know the user make our application can't access to her/his gps to know his/her location? because my application need CurrentLocation, so if I can detect what user choose, I want to make a Pop Up like first Pop Up that asking for permission again.

or any code that can make gps turn on/off by my application?

Imagine if the user does not allow by mistake? Is there away for my application to reask the user?

What should application like Yelp do when location is not available?

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

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

发布评论

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

评论(2

叶落知秋 2024-12-03 11:58:52

从 iOS 4.2 开始,您要在其上实现 CLLocationManagerDelegate 方法的类(例如 -locationManager:didUpdateToLocation:fromLocation:)也应该实现 -locationManager:didChangeAuthorizationStatus:。该方法将收到四种状态;要检查您的应用是否无法使用位置服务,请查找 kCLAuthorizationStatusRestricted(当用户无法允许访问位置服务时)和 kCLAuthorizationStatusDenied(当用户明确指定时)拒绝您的应用程序访问位置服务。在这两种情况下,适当的做法是通知用户(通过警报视图或其他方式)您的应用程序依赖于能够访问他们的位置,并且他们可以在“设置”应用程序中重新授予其访问权限。您还可以使用 CLLocationManager 类方法 +authorizationStatus 随时检查应用的授权状态。

不幸的是,4.2 之前的版本都不可用,您需要使用 sosbom 的答案提到的 +locationServicesEnabled 方法。

As of iOS 4.2, the class on which you’re implementing CLLocationManagerDelegate’s methods (like -locationManager:didUpdateToLocation:fromLocation:) should also implement -locationManager:didChangeAuthorizationStatus:. There are four statuses that that method will receive; to check for your app being unable to use location services, look for kCLAuthorizationStatusRestricted—when the user is unable to allow access to location services—and kCLAuthorizationStatusDenied—when the user has explicitly refused your application access to location services. In both cases, the appropriate thing to do is to inform the user (via an alert view or whatever) that your application relies on being able to access their location and that they may be able to re-grant it that access in the Settings app. You can also check your app’s authorization status at any time using the CLLocationManager class method +authorizationStatus.

Pre-4.2, unfortunately, none of that is available, and you’ll need to use the +locationServicesEnabled method that sosbom’s answer mentions.

恰似旧人归 2024-12-03 11:58:52

阅读以下内容:位置感知编程

关键是:

确定位置服务是否适用于每个基于 iOS 的设备
设备能够以某种形式支持定位服务,但是
仍然存在位置服务可能无法使用的情况
可用:

用户可以在“设置”应用程序中禁用位置服务。
用户可以拒绝特定应用程序的定位服务。这
设备可能处于飞行模式并且无法启动必要的电源
硬件。由于这些原因,建议您始终致电
之前CLLocationManager的locationServicesEnabled类方法
尝试启动标准位置或重大更改位置
服务。 (在 iOS 3.x 及更早版本中,检查
改为 locationServicesEnabled 属性。)如果此类方法
返回YES,即可按计划启动定位服务。如果返回的话
不,并且您无论如何都尝试启动定位服务,系统
提示用户确认是否需要定位服务
重新启用。鉴于定位服务很有可能被禁用
用户可能故意不欢迎此提示。

Read this: Location Awareness Programming

The key line is this:

Determining Whether Location Services Are Available Every iOS-based
device is capable of supporting location services in some form but
there are still situations where location services may not be
available:

The user can disable location services in the Settings application.
The user can deny location services for a specific application. The
device might be in Airplane mode and unable to power up the necessary
hardware. For these reasons, it is recommended that you always call
the locationServicesEnabled class method of CLLocationManager before
attempting to start either the standard or significant-change location
services. (In iOS 3.x and earlier, check the value of the
locationServicesEnabled property instead.) If this class method
returns YES, you can start location services as planned. If it returns
NO and you attempt to start location services anyway, the system
prompts the user to confirm whether location services should be
reenabled. Given that location services are very likely to be disabled
on purpose, the user might not welcome this prompt.

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