【发布时间】:2014-07-08 18:15:16
【问题描述】:
例如,找到位置并将其上传到服务器。 我需要在应用关闭时找到用户位置并将其上传到我的服务器。
【问题讨论】:
标签: ios background core-location
例如,找到位置并将其上传到服务器。 我需要在应用关闭时找到用户位置并将其上传到我的服务器。
【问题讨论】:
标签: ios background core-location
这可以在 iOS 6.x 及以下版本中完成
当应用第一次进入后台时,调用 UIApplication 类的 beginBackgroundTaskWithExpirationHandler 方法。
这将为您的应用额外提供 10 分钟的时间 在这 10 分钟到期之前,使用 startUpdatingLocation 临时启用细粒度位置更新,然后使用 beginBackgroundTaskWithExpirationHandler 方法请求更多时间。
临时启用位置更新会神奇地重置 10 分钟的后台宽限期。因此,该应用可以在其“租约”到期之前定期续订,并无限期地在后台运行。
以下是详细的演练:
http://gooddevbaddev.wordpress.com/2013/10/22/ios-7-running-location-based-apps-in-the-background/
【讨论】: