CLLocationManager 初始化

发布于 2024-12-04 18:17:46 字数 348 浏览 0 评论 0原文

我正在开发一个网络应用程序,该应用程序允许用户仅在特定位置登录。我正在使用 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技术交流群

发布评论

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

评论(2

花期渐远 2024-12-11 18:17:46

听起来您已经正确编码了位置信息。您缺少(但已经看到)的是更新肯定不会立即发生。您需要在位置信息可用时“控制”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. :-)

甩你一脸翔 2024-12-11 18:17:46

您需要在应用程序 UI 中考虑初始 nil 值并等待第一次位置更新。

-地点

讨论
如果没有位置数据,则此属性的值为 nil
曾经被检索过。

最好检查所在位置的时间戳
回来了。如果接收器当前正在收集位置数据,但是
最小距离过滤器较大,返回的位置可能是
比较旧。如果是,您可以停止接收器并重新启动它
强制更新

您还应该查看 Region监控,因为您希望您的用户只能在特定位置登录。

You will need to account for an initial nil value in your applications UI and wait for the first location update.

-location

Discussion
The value of this property is nil if no location data has
ever been retrieved.

It is a good idea to check the timestamp of the location that is
returned. If the receiver is currently gathering location data, but
the minimum distance filter is large, the returned location might be
relatively old. If it is, you can stop the receiver and start it again
to force an update

Also you should check out Region Monitoring since you would like for you users to only be able to login at specific locations.

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