如何在 iPhone xcode 上检测 GPS 的开/关以及我们如何知道我们的应用程序不允许使用 GPS?
我想制作将使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 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 forkCLAuthorizationStatusRestricted
—when the user is unable to allow access to location services—andkCLAuthorizationStatusDenied
—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.阅读以下内容:位置感知编程
关键是:
Read this: Location Awareness Programming
The key line is this: