iPhone上运行周期性进程在后台 - 电池优化的方式 [英] iPhone running periodical process in the background - battery optimized way

查看:275
本文介绍了iPhone上运行周期性进程在后台 - 电池优化的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在后台运行特定的任务。这个任务需要几秒钟即可完成(它的一些GPS定位数据写入文件)。这个任务应该运行一次,每隔1小时。

I want to run a specific task in the background. This task takes few seconds to complete (it writes some GPS location data to a file). This task should run once every 1 hour.

当我从SDK明白了,我没有办法来启动的东西在后台,除非我运行位置服务到永远。当该服务运行时,它给我不时的事件,我能够在这些调用运行我的code。我试了一下,甚至与最低precision可能的话,我的电池很快会下降。

As I understand from the SDK, I do not have a way to INITIATE something in the background unless I run Location Services forever. When this service runs, it gives me an event from time to time, and I'm able to run my code during these calls. I tried it, and even with the minimal precision possible, my battery goes down very quickly.

所以,我正在寻找一种方式来运行定位服务几秒钟每隔一小时。所有的时间,我不想剩下的运行位置服务,我不希望使用的电池。

So, I'm looking for a way to run Location Services for few seconds every hour. All the rest of the time I do NOT want to run Location Services and I do NOT want to use the battery.

你能有所帮助吗?
谢谢,

Can you help here please? Thanks,

吉纳

推荐答案

什么是你真正想知道每隔一小时?你们是不是要准确地确定位置,或者只是确定手机已经显著感动? startMonitoringSignificantLocationChanges 将通知您的时候,手机移动显著(这通常意味着更改单元格塔)。在城市这个可以很经常发生。 startMonitoringForRegion:desiredAccuracy:当你移动一个给定的半径之外,只会通知您

What do you actually want to know every hour? Are you trying to determine the location accurately, or just determine if the phone has moved significantly? startMonitoringSignificantLocationChanges will notify you when the phone moves "significantly" (which generally means changing cell towers). In cities this can happen quite often. startMonitoringForRegion:desiredAccuracy: will only notify you when you move outside of a given radius.

startMonitoringSignificantLocationChanges 是pretty便宜。它主要依赖于细胞天线,这是一般的反正。如果触发一次一个多小时,你总是可以跳过处理并返回。但谁也不能保证,你会被调用一次一个小时,特别是在农村地区。

startMonitoringSignificantLocationChanges is pretty cheap. It mostly relies on the cell antenna, which is generally on anyway. If it fires more than once an hour, you could always just skip processing and return. But there's no guarantee that you'll be called once an hour, particularly in rural areas.

如果你是一个VoIP的应用程序,那么你可以注册一个周期性的签间隔时,您可能会遇到code。但你不能对位置信息的应用做到这一点。

If you are a VoIP app, then you may register a periodic "checkin" interval when you may run code. But you cannot do this for location apps.

您使用异形能源诊断仪器的code?什么是真正吃的时间和力量?您是否正在广播,CPU,磁盘嚼?

Have you profiled your code using the Energy Diagnostics instrument? What's actually eating time and power? Are you chewing on the radio, the CPU, the disk?

修改

在应用程序死亡,重大的变化仍然继续运行,并留下一个小的方向箭头图标旁边的百分比iPhone的顶部工具栏上。我的用户抱怨的图标仍然查杀应用程序后,

When the app dies, Significant Changes still continue to run and leave a small direction arrow icon next to the percentage on the top toolbar of the iPhone. My users complain that the icons remains after killing the app

之后,如果你注册了显著的变化,你会期望在响应他们被重新启动。如果你想在的情况下注销你在哪里结束,你可以添加 stopMonitoring ... 你的 applicationWillTerminate:方法。这并不能保证被调用,但它是做一件好事,我相信,如果用户直接终止你就会被调用,你没有暂停(没有测试过)。

After the app dies, if you were registered for significant changes, you would expect to be relaunched in response to them. If you want to unregister in cases where you are terminated, you can add stopMonitoring... to your applicationWillTerminate: method. This isn't guaranteed to be called, but it is a good thing to do, and I believe it will be called if the user terminates you directly and you were not suspended (haven't tested that).

再次显著位置的变化应在电池寿命方面极其便宜只要有小区覆盖。他们不应该强迫GPS留任。

Again, significant location changes should be extremely cheap in terms of battery life as long as there is cell coverage. They should not force the GPS to stay on.

这篇关于iPhone上运行周期性进程在后台 - 电池优化的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆