如何让应用程序永远以后台模式运行?
我遇到了一个关键问题,让我与您分享。 我有一个 iPhone 应用程序,无论应用程序处于后台模式还是前台模式,每分钟都需要将当前位置发送到服务器。 我完成了 info.plist 参数中的属性设置,例如后台模式 - >位置和位置配置的其他代码通常是
- (CLLocationManager *)loc_mngr { if (loc_mngr != nil) { return loc_mngr; } loc_mngr = [[CLLocationManager alloc] init]; loc_mngr.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; loc_mngr.delegate = self; return loc_mngr; }
loc_mngr 是 CLLocationManager 的对象。 委托方法实现完成。 它对我有用,但问题是当我的应用程序在后台时如何启用位置服务。 请帮我如何处理? 副词中的感谢
i got one critical problem let me share with you .
i have an iphone app that need to send current location to server whether app is on background mode or foreground mode per minute.
i done setting property in info.plist parameter like background mode-->location and other code for location configuration is usual
- (CLLocationManager *)loc_mngr { if (loc_mngr != nil) { return loc_mngr; } loc_mngr = [[CLLocationManager alloc] init]; loc_mngr.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; loc_mngr.delegate = self; return loc_mngr; }
loc_mngr is an object of CLLocationManager.
delegate method implementation is done.
it work for me but the problem is how to handel location service enable when my app is on background.
please help me how to deal with it?
thanks in adv.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看这个苹果文档,您可以使用以下方法来完成此操作。
然后,向框架注册区域:
委托协议定义了用于区域的三种方法:
Have a look at this apple document, you are having following methods to do this thing.
And then, register the region with the framework:
The delegate protocols define three methods to use for regions:
您将需要创建一个 CLLocationManagerDelegate 来接收对您的应用程序的回调。您需要设置要运行的位置项,并且当您的应用程序转到后台时,您需要让委托“监听”位置更新。这可以通过区域监控 -didEnterRegion 或 -didExitRegion 来实现。或者像标准位置监控中的 -didUpdateToLocation 一样简单。
有关更多信息,请阅读 Apple 位置感知编程指南。祝你好运。
You will need to create a CLLocationManagerDelegate to receive the callbacks to your app. You need to set the location item to run, and when you app goes to the background, you need to have the delegate "listen" for location updates. That can be via region monitoring -didEnterRegion or -didExitRegion. Or as simple as -didUpdateToLocation from standard location monitoring.
For more information, read Apple's Location Awareness Programming Guide. Good luck.
“永远”这个词在概念上是错误的:苹果保留随时终止应用程序的权利。你需要重新考虑逻辑。
一些注意事项:
始终打开本地化(标准本地化)是错误的:它会很快消耗电池
是更好用:
[locationManager startMonitoringSignificantLocationChanges];
这种方式功耗要少得多(即使精度较低...)
The term "forever" is conceptually wrong: Apple retains the right to kill apps at any moment. You need to reconsider the logic.
Some notes:
it is wrong to keep localization (standard localization) always on: it consumes battery very quicky
is better to use:
[locationManager startMonitoringSignificantLocationChanges];
This way power consumption is much less (even if precison is lower...)