CLLocationManager 初始化
我正在开发一个网络应用程序,该应用程序允许用户仅在特定位置登录。我正在使用 CLLocationManager,并在 AppDelegate -didFinishLaunchingWithOptions
处初始化并调用 startUpdatingLocation
。我的 UIWebView 应该在初始化时提取位置以确定用户是否位于指定位置内。但是,在启动我的应用程序时,[locationManager location]
始终为 null,并且在初始化并显示 UIWebView 之后更新,因此已经向用户发送错误消息。
如何让我的 locationManager 在初始化时更新其位置?
I'm working on a web application that enables users to login, only at specific locations. I'm using CLLocationManager and I initialized and called startUpdatingLocation
at AppDelegate -didFinishLaunchingWithOptions
. My UIWebView is supposed to pull the location at initialization to determine whether user's within the specified locations. However, at the launch of my application, [locationManager location]
is always null and updates after my UIWebView is initialized and displayed therefore already sending an error message to the user.
How do I make my locationManager update its location at initialization?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您已经正确编码了位置信息。您缺少(但已经看到)的是更新肯定不会立即发生。您需要在位置信息可用时“控制”UI 演示文稿的其余部分(即您的网络视图)。有很多方法可以做到这一点。一种常见的策略是向用户展示一个全屏“HUD”或带有一些指示器的“面纱”,表明应用程序正在初始化或定位它们(带有活动指示器,总是一个很好的触摸。)在其后面(看不见)给用户)您可以等待位置结果,然后启动相应的 UI 更新,然后放下面纱。
其中任何一个有意义或者给你一些想法吗?我已经做过很多次了。将异步活动(例如位置更新)与有意义的实时 UI 更新同步可能具有挑战性,但并非不可能。 :-)
Sounds like you've coded the location stuff correctly. What you are missing (but have seen) is that the update most certainly does not happen instantaneously. You need to "gate" the rest of your UI's presentation (i.e. your webview) on the location information becoming available. There are a lot of ways to do this. A common tactic is to present a full-screen "HUD" or veil with some indicator to the user that the app is initializing or locating them (with an activity indicator, too, is always a nice touch.) Behind that (out of sight to the user) you can be waiting for the location result and then kickoff the appropriate UI update, and then drop the veil.
Any of that make sense or give you some ideas? I've done this plenty of times. Synchronizing async activities (like location updates) with real-time UI updates that make sense can be challenging, but isn't impossible. :-)
您需要在应用程序 UI 中考虑初始 nil 值并等待第一次位置更新。
-地点
您还应该查看 Region监控,因为您希望您的用户只能在特定位置登录。
You will need to account for an initial nil value in your applications UI and wait for the first location update.
-location
Also you should check out Region Monitoring since you would like for you users to only be able to login at specific locations.