iPhone Application: Best Practices for Minimizing Battery Usage? - iphone

What are the major factors that might cause an application to consume more battery power?
As an iPhone app developer, what best practices can I apply to minimize battery use?

Minimise CPU usage.
Use a profiler to find hot-spots in your code. Unlike desktop apps, where the goal is "fast enough," here, the goal is, "as little CPU as is humanly possible."
Read up on background operation, because the way your app behaves in the background can have a significant effect on battery life.
Avoid telling the app not to sleep via UIApplication.idleTimerDisable. If you need to use it, turn it on an off as a appropriate, rather than disabling it once at application startup time.
Try to only keep OpenGL render loops running if the scene is changing.

Related

Side effects of a iphone app

is there a way to measure side effects of a iphone app on other apps performance? at least using a black-box focus.
Any suggestion about a monitorization app with this orientation?
I have found that my app can know nothing about other apps, but I would like to measure some kind of impact of my app on the rest of applications, or in case it is not possible make estimations about the overall system performance.
Thanks for your help
In most cases your app will not run when another app is in foreground. There are only quite few reasons you are allowed to keep your app running in the background. If your app is one of these, Instruments gives you a great way to analyse performance not only on your app but on the hole device. Have a look into the WWDC2012 session 235 videos. It deals with app performance and analysis thru Instruments.

Tricks to make app more efficient on battery consumption.(iOS)

Are there any tricks/methods to optimize the battery usage that you app uses?
I've an app that can play streaming audio in the background quiet well. It does the basics like put the app in the background after a little time of no interfacing with the screen by the user.
Are there any other tricks to be done to stop it eating the battery like a fat man at an all you can eat buffet!
Thanks,
-Code
You can decrease the usage of the internet and in the case that you are using the Location librairies don't use them except if you need them in which case don't use cutting eye accuracy. The most valid trick for this is no GPS no Geolocation.
I hope this helps!
Reading in data over a network connection is one of the most power hungry operations on the device. Depending on your protocol, you maybe able to optimize the streaming by buffering larger chunks at a time (if possible). Obviously if this is realtime streaming of a live feed that is not an option.
Review Apple's guidelines here: Performance, make sure you scroll down to the Reduce Power Consumption section. Basically, to reduce power consumption, you should do as little as possible. If you are turning on frameworks like CoreLocation or using the accelerometers, you should disable those as often as possible. Try releasing as many resources as you possibly can when in the background. Less memory means less overhead for the system to keep track of as well.

Minimising an app's battery usage on iOS (while phone is locked etc)

I've noticed that since iOS 4.0, the apps I developed started to not "exit" when the home button is pressed, but rather they stay in the "system tray" thing which pops out when you double click the system.
At around the same time, I noticed that the battery in my phone starts draining a lot faster. Then again, theoretically all the app should be using right now is only memory, because it is not currently active.
Which begs the question, has there ever been any benchmark on what causes the iPhone to drain the most batteries? Perhaps opengl calls, which use the graphics card would consume quite a bit? Or maybe just having the apps active mean there's less memory, and this causes faster battery loss (say, because the memory allocator must do more work etc)?
I am keen to know what other developers have tried to do to optimise battery usage.
its not opengl or allocations that cause the battery drain in fact the variables are saved on the hard disk when the application quit. They don't stay in memory cause this wouldn't be possible with running all apps at the same time. (see comments)
special thanks to Stephen Furlani for this guide in documentation
I think the only ones that can cause the faster drain are background processes that still accepted to be run in background like the voice over IP feature from Skype. (the features where big announced at the iOS 4 SDK preview back then). Background audio/video, network transfers like pandora etc. (I can't name all) but not every app!
And by the way, I also noticed that my battery sometimes not hold as long as possible on other days. But I can't locate which App cause that :(

What kind of bugs have you fixed due to energy inefficiency issues when you develop mobile apps [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
For those who write applications for mobile phones, what kind of bugs/problems have you fixed in order to improve energy efficiency, and how much the fix improves?
A follow-up question: is energy efficiency considered as important as features and avoiding functionality bugs when you write mobile apps?
To answer the follow-up question first, very few customers notice any difference in energy efficiency or battery life from using a particular app. This is almost never mentioned in the App store reviews. I write power efficient code mostly because I don't want to run down my own device's batteries while testing and using my apps.
Some suggestions for iPhone apps:
Write your app so that it runs well on the slowest device (iPhone 2G or 3G) with the slowest OS (4.x on a 3G). Then it can mostly be idle on the much faster current devices.
In graphics routines, try not to redraw anything already drawn. Use a small CALayer or sub view for localized graphics updates/changes.
Use async methods as much as possible so that your app isn't even running on the CPU most of the time.
Use plain C data structures (instead of Foundation objects) and pack them so that your app's working set can stay completely resident in the very limited ARM CPU data cache, if possible.
Don't do networking any more than necessary. Do the largest data transfers possible at one time so that the radios can turn off longer between your app's network use, instead of lots of continuous small transfers.
Energy efficiency in mobile dev is tantamount to memory constraints in embedded systems.
Specifically, I like GPS apps and so make sure that the GPS is only on for the bare minimum of time. Of course, when there are bugs that are introduced that keep the GPS turned on too long they go to the top of the list to get fixed.
So, the short answer is: Yes, energy efficiency is definitely as important as features.
EE is important especially if the application is running constantly in the background.
We had to replace polling methods with event based methods whenever possible. If it was not possible we reduced the polling frequency.
Also reducing file read/writes to minimum reduces battery consumption considerably.
Process images + calculations on the server for low cpu phones rather than using the phones cpu (not as applicable on iPhone + Android handsets)
Draw to the screen only when necessary rather than endlessly
Save state at all times so the user can enter the application where they left off if an interrupt causes your application to be placed into the background
Avoid running in the background where ever possible? do you really need to or can wait until the application has focus
Avoid using fine grain location where a coarse location would do (GPS vs cellular location)
Use push over pull where ever it is possible to save polling the network
In my opengl based live wallpapers battery life is a significant issue.
Keep sensor use to a minimum, there is lots of different profiles, use the delay that you require.
To maximize battery in a LWP I usually force a frame delay of 5ms by default. This appears to be enough time to let the CPU relax between frames and keep the usage reasonably low. You can also manage the timeout based on the current FPS and pin it to a FPS profile. E.g. the device could render 60fps, but you are just rendering at 30fps and sleeping half the time.
For games you could do the same, just put a fps limit in your engine and don't let it go above that.
If you want to be hardcore, realize that OLED's used in many android devices use more power to display light colors as opposed to dark ones. On a LCD there is a equal backlight, but on OLED a black pixel is effectively off and not using power. So the darker your screen, the longer your battery life should last. Something to consider in certain situations if you want to be really hardcore on the battery side of things.
Don't use the GPS, don't use 3G, and if you do cache everything locally.

Background app drains too much battery

I have developed an application for iPhone that runs in the background with GPS mode on. I need to ask the server if there are any new tasks for the user? Fir this purpose, I have added the code in the didUpdateToLocation method. Now the problem is that it consumes the battery very fast. Please guide me how to avoid the battery consumption. Also, I need to keep the location accuracy at best.
Also, is there any other way where I can communicate to the server even while the app is running in the background. Please help me, I will be really grateful.
It is impossible to get accurate location without using internal GPS in the current state of iPhone. Since essentially you are keeping the GPS alive during the running of the app (not sure if Multitasking API allows GPS calling in background though), it would consume lots of battery power without doubt.
In this case, you either have to avoid calling GPS as much, or live with coarse locations from the cellar towers. You can't have both frequent GPS results and nice battery consumption.