ios - 尽管用户已终止应用程序并检查 iOS 中的设备位置,如何保持 iOS 应用程序进程始终运行?

标签 ios objective-c gps cllocationmanager

我需要每隔一小时左右检查一次设备位置,如果该位置在特定区域之外(例如设备已被带出办公场所),请执行一些操作(例如显示本地通知“嘿!设备在办公室外面”)。

为此,即使应用程序被终止,我也需要每隔一小时检查一次位置。如何让应用程序永远保持活力,尽管它已被用户终止。

最佳答案

是的,您可以这样做,但如果您的系统是部署目标,则大于 7.0。

在 ios7.1 中有一个方法叫做 startMonitoringSignificantLocationChanges .此方法在后台更新位置,即使应用程序根据苹果文档终止:

Starts the generation of updates based on significant location changes.

If you start this service and your app is subsequently terminated, the system automatically relaunches the app into the background if a new event arrives. In such a case, the options dictionary passed to the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods of your app delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your app was launched because of a location event. Upon relaunch, you must still configure a location manager object and call this method to continue receiving location events. When you restart location services, the current event is delivered to your delegate immediately. In addition, the location property of your location manager object is populated with the most recent location object even before you start location services.



我为此找到了一个演示,可能会对您有所帮助。看这个链接http://mobileoop.com/getting-location-updates-for-ios-7-and-8-when-the-app-is-killedterminatedsuspended

关于ios - 尽管用户已终止应用程序并检查 iOS 中的设备位置,如何保持 iOS 应用程序进程始终运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29763564/

相关文章:

gps - 如何将地理空间坐标从右上角、左下角转换为左上角和右下角

android - 整个应用程序中只有一个 LocationListener

ios - 如果我在同一 View 上有两个 ImageView ,如何区分哪个 UIImagePickerController 调用 func didCancel?

ios - 在 iOS 中使用 GTLGmailMessage 阅读电子邮件

objective-c - UIToolbar 中的 UISlider -> 无法获取 slider.value 并对其进行处理。 iOS 开发工具包

objective-c - UILabel attributedText 和 minimumScaleFactor

c++ - 我可以在同一个 Xcode 项目中拥有 Swift、Objective-C、C 和 C++ 文件吗?

iphone - 将 iPhone 或 iPod 变成无线网络摄像头

android - NSnull 类型的 JSON 值无法转换为 NSString

vb.net - 在 .net 桌面应用程序中访问 Windows 10 上的位置