简体   繁体   中英

How to save accelerometer data in the background on iOS?

I am developing an activity recognition/tracking app that provides the user with statistics and a timeline of their day. I currently have a working version for iPhone 5S and above that uses the M7 and M8 motion co-processor to query activity for the past day or time period.

I am now attempting to develop a version that is supported by older phones such as the iPhone 5 and 5c (without the M7/M8 motion co-processor). My idea is to save accelerometer readings for a period of time, and send them to a server to be classified, but I cannot get the app to stay alive in the background for longer than a few minutes in order to detect and save these readings.

I have used CLLocation updates to attempt to keep the app alive in the background, but like our version for newer phones, it only wakes the app up for about 10 seconds on each location update rather than keeping it running continuously in the background.

I am also aware of tricks/hacks that can be used to such as registering for the Audio or VOIP background modes but this will only get our app rejected by Apple's review system if those modes aren't used for a user-facing feature.

Other answers on Stack Overflow vary from saying that it's not possible at all, to saying that it's easy when using location updates - any idea what I am missing here?

There are apps on the App Store such as Moves and Human that work for iPhones without the M7/M8 motion co-processor - does anyone have any idea how these work?

If you haven't already, take a look at the latest Background Execution docs as they are really explicit on how to do processing when the app is not active, including what is and what is not allowed.

https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

The only way you can get close to what you want is to enable standard location services in the background using a high level of accuracy (eg desiredAccuracy = kCLLocationAccuracyBest). The high accuracy will keep the updates coming in most cases other than the user standing still. You should have a good business reason to use this feature so come up with one if you don't. Also keep in mind that this is heavily draining on the battery and warn your users about this in advance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM