最佳实践-iPhone后台应用模式

发布于 2024-09-16 05:08:23 字数 1536 浏览 2 评论 0原文

我目前正在测试最新的 iOS4 功能,将我的位置感知应用程序置于后台。嗯,它确实有效!但另一方面,处理巨大的电力使用却相当困难。

该应用程序在过去四个小时内消耗了约 50% 的电池电量。它读取 Apple 关于此主题的整个官方文档,但我仍然不确定应用程序的哪些部分仍在运行以及哪些功能已暂停(除了 UI 绘图之外,应该很清楚) 。

我不使用任何真正的样板代码,而是使用 ASIHTTPRequest 之类的扩展库来与我的网络服务通信。使用朋友的汽车进行的测试是否表明,当我使用 ie

[locationManager startMonitoringSignificantLocationChanges];

有关不同应用程序状态的 Apple 文档

后台:应用程序位于后台并执行代码 [...]

我应该编写一个“裸机”函数来接收和发送该位置数据吗?当应用程序驻留在后台时,我是否应该删除所有其他对象以减少内存占用?似乎还没有任何最佳实践。

有什么想法吗?也许你们可以向我提供一些你们的见解。谢谢。

编辑: 有一个名为 能源诊断仪器记录连接设备的任何电量使用情况(适用于 iPhone 3GS 及更高版本)。此外,设备上的“设置”应用程序中还有另一项服务 ->开发商->电力使用情况。在现场测试您的电量使用情况非常棒。创建的日志可以稍后在仪器中提取。

参考:WWDC 2010 第 309 场会议 - 使用仪器进行高级性能分析

I'm currently testing the latest iOS4 Feature to put my location aware app in the background. Well, it does work! But on the other hand it's quite hart to handle the immense power usage.

The app consumed about 50% battery power in the last four hours. It read the entire official documentation by Apple on this topic but I'm still not sure which parts of my application are still running and which functionality is suspended (beside the UI Drawing, which should be clear).

I don't use any real boilerplate code but extended libraries like ASIHTTPRequest to talk to my webservice. Tests with a friends car did you show that the Network Connectivity and and the Location Services is still running when I'm using i.e.

[locationManager startMonitoringSignificantLocationChanges];

Apples Documentation on the different application states

Background: The application is in the background and executing code
[...]

Should I write a "bare metal" functions to receive and send this location data? Should I remove all other objects for the time the application resides in the background to reduce the memory footprint? It seems there isn't any best practice yet.

Any ideas? Maybe you guys can provide me with some of your insights. Thanks.

Edit:
There's a new Instruments tool called Energy Diagnostics Instruments to record any power usage (for iPhone 3GS and later) with an attached device. Also there's another service on the device in the Settings App -> Developer -> Power Usage. It's great to test your power usage in field. The created logs can be pulled later in instruments.

Reference: WWDC 2010 Session 309 - Advanced Performance Analysis with Instruments

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(1

别靠近我心 2024-09-23 05:08:23

听起来您的应用程序正在通过蜂窝网络传输位置数据。打开蜂窝无线电是导致电力耗尽的最快速原因之一,特别是当用户与蜂窝塔的信号连接较弱时。

您可能想要保存并打包一堆位置数据,并尽可能少地快速发送数据(每天两次,当用户停止移动 30 分钟时,仅在用户到达他们最喜欢的位置之一后)餐馆等)将收音机打开的次数减少一半可以使电池寿命接近加倍(除非用户还使用设备执行其他操作)。

Sounds like your app is transmitting location data over the cellular network. Turning on the cellular radio is one of the most rapid causes of power drain, especially if the user has a weak signal connection to the cell tower.

You might want to save and package up a bunch of location data, and send the data in a quick burst as seldom as possible (twice per day, when the user stops moving for 30 minutes, only after the user gets to one of their favorite restaurants, etc.) Turning on the radio less than half as often could get you close to doubling the battery life (unless the user is doing something else with the device as well).

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