CoreMotion updates in background state

前端 未结 5 1859
迷失自我
迷失自我 2020-12-02 06:57

With the M7 chip in the latest iOS devices one can get programmatically notified as the user goes from stationary to running, walking, etc using CMMotionActivityManager. Sta

相关标签:
5条回答
  • 2020-12-02 07:18

    What I noticed when you turn off GPS, app will not execute any code in background for iOS 7, app looks like in inactive state. So better while moving to background use startMonitoringSignificantLocationChanges and also get updates from your location manager. Means simultenoulsy use both service startUpdatingLocation on user state change and startMonitoringSignificantLocationChanges in Background.

    So when user Turn on GPS, while you used startMonitoringSignificantLocationChanges your app will receive

    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    

    Better check here in background itself what wrong with CoreMotion Framework. And try to restart it. Because wihtout M7 chip device I am able to read Accelerometer reading in such case.

    0 讨论(0)
  • 2020-12-02 07:22

    RunKeeper actually does use the audio trick to stay awake. If you open up the app package and check their Info.plist you will see that it registers for the background audio mode. This is how they pull off periodic audio notifications of your distance, speed, and pace. It is also how they stay awake during your run while minimizing battery drain.

    If you noticed that the Location Services icon (the triangle in the status bar) disappears completely while using RunKeeper then they definitely are not using any type of location tracking to accomplish background execution. Even activating geo-fences and significant location change monitoring would cause the Location Services icon to appear.

    They also aren't using the M7 to stay awake because it doesn't work that way. An update from the M7-related CoreMotion APIs will not wake up your app from sleep. When they app does wake up they would be able to query the Motion Activity and Step history and maybe try to compute something, but I doubt it would be all that accurate.

    Finally you should note that the Auto-pause APIs were introduced in iOS 6 before the release of the iPhone 5s and M7 chip. They are orthogonal concepts.

    0 讨论(0)
  • 2020-12-02 07:25

    If your location manager is working in Active mode, to enable background mode you need to do this three steps:

    1. Check that [Target / Capabilities / Background Modes / Location updates] is enabled.
    2. [locationManager requestAlwaysAuthorization];
    3. locationManager.allowsBackgroundLocationUpdates = YES;
    0 讨论(0)
  • 2020-12-02 07:28

    have you considered experimenting with

    application:performFetchWithCompletionHandler: 
    

    in the app delegate? You can't control how often it is called, but depending on the app, it can be every ~15 minutes. You can then launch the CMMotionActivityManager from there to query M7 results.

    It's not entirely clear what functionality you are trying to replicate, but the M7 chip records all of the activity, regardless of whether your app is running. So you can simply query in the background and update step totals or activity type totals.

    0 讨论(0)
  • 2020-12-02 07:31

    First, check if you have set up the background behave of your app.

    Go to target - capabilities section and check Background mode for location updates.

    XCode Capabilities

    0 讨论(0)
提交回复
热议问题