Get data from accelerometer when application runs in the background - iphone

So I need my iphone application to run in the background and collect data from the accelerometer. Even though I managed to do the former by playing background music, the accelerometer seems to stop sending data to the application when the app is not in theforeground.
Is there any workaround for this?
I've seen there's a trick to make it not go asleep:
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
... but my problem is that I have to run and see the GUI of another application when this other one is running.
Thanks.
P.S. I know the app store would reject my application. My project is only for demostration purposes.

Related

How to implement in code to save battery life but keep iphone application live?

I have an iPhone application which does audio recording. What I want to achieve is to keep the application alive to do continuos recording but at the same time save battery life i.e. save power consumption
Just a note, I have used following code to keep application alive.
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
I don't think there is any way to instantly 'save battery life'. Only thing you can probably do is minimize read/write operations, internet access etc. This you have to manually do in code.

Why does my iPhone App continue in the background?

I wrote my first iPhone App, and managed to get it into the App store. I later discovered a bug that happens on a real device but not on my emulator. I have committed a fix (changed plist to prevent app running in background), but I don't really understand why it happened.
My App allows users to record a sound-byte, however while they are recording they can use the iPhone home button to move the app to the background, and then it can keep recording forever if they don't restart the phone or the app does not crash.
My impression from everything I have read, is that this should not happen as you have to ask for background audio specifically if you want to do this, but now it appears to me that you have to ask specifically to disable it.
Could anyone explain this to me?
The iOS App lifecycle is described in Apple's iOS App Programming Guide.
The App is given the opportunity to save data and otherwise stop things that don't need to be running, before being suspended. You can request extra time doing this by using beginBackgroundTaskWithExpirationHandler:.
If you want your app to stop doing its "normal thing" when it is put into the background then you need to detect the App state transition and stop it yourself.

iPhone4, how to stop an application being suspended?

I am trying to test an application that needs to run over an extended period of time and to aid initial testing I am trying to find a way to stop iOS moving the application to the background and suspending it. Ultimately I will add code to facilitate the use of multi-tasking but right now I just want to better test the core mechanics without iOS pushing it into the background all the time.
You can not prevent ios from suspending an app. The home button will close/resign active the application and even if you request for a background task apple can kill your app at any time as it sees necessary (More than likely for memory reasons).
As long as you, the user, don't stop this app, launch another app, or lock the device:
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
might keep your app running in the foreground. Don't forget to re-enable the idle timer, or this could keep the device running until the battery is dead.

iPhone background network connection by timer

I need to write an application, that every 10 minutes it should be awaken from suspended mode, get user location via gps and send this information to the server by network.
Depending on the response it should return to the suspended mode or show local notification to the user.
Is there a way to do this on iOS 4?
I've tried different approaches, but the only working for me was to start monitoring user location in backgroind and declare the application as location background application. In that case it worked in background and has a network connection. But this approach takes a lot of power and not accepted cause application should work 24/7.
May be there is a way to write some daemon that should work in background and wake my application every 10 minutes?
Apparently, Pastebot tried to do something similar with the 'audio' multitasking declaration (by playing a silent audiofile) and got rejected.. UNTIL they actually presented a option to the user to pick which audiofile they wanted to play. It's in the appstore now. :)
In this case: What is your reason for not wanting to use the location updates? If battery-usage is a concern, you can use the 'significant location changes only' option, after which you can temporarily change to a more accurate option.
This isn't possible outside of the method you have already tried.
The iPhone background task API will allow you to run a location service in the background.
There is no way to write daemons for the iPhone without jailbreaking, and that is not something I'm able/prepared to help you with.
App store friendly: use new APIs in iOS4, which allows u to make use of GPS location
Anti App store: create a daemon by adding a specific plist file to System/Library/LaunchDaemons/ and put ur app under Applications/. this approach requires a jailbroken iPhone however...
detailed information plz google the following keywords: daemon, multitask, background, etc...
cheers, Lloyd

Is it possible to run accelerometer of iPhone in background?

I want to use accelerometer of iPhone to get the log file of accelerometer value (maybe for 24 hours). Is it possible to let accelerometer runs in background while other applications are running?
You can do it now, if your app is allowed to run in the background for other reasons. See the Core Motion API's startAccelerometerUpdatesToQueue:withHandler: method here.
Nope, it is not. You basically can't run anything but a music app in the background.
You can run the accelerometer while the phone is suspended though.
See this blog for how to do it: http://marcopeluso.com/2009/08/23/how-to-prevent-iphone-from-deep-sleeping/
I use this technique in my GPS recording app.
No, it is presently not possible, at least if you want to distribute your application through the App Store.