3 Replies Latest reply: Nov 20, 2012 10:37 AM by xnav
Kumar007 Level 1 Level 1 (0 points)

HI there,    

               I am doing a somewhat strange implementation.Here is what my application does. My application is basically using GPS data continously and using that i have to do some task. Also i have implemented Accelemeter stuff to detect device is idle or is in move.When device is in idle i am stopping gps fetching by calling "stopUpdatingLocation". and when device is in move call "startUpdatingLocation". This works fine both in foreground and background.

     But I want my application to be started(in background) when device is restarted.This works fine. I have added "voip" key in plist and in "applicationdidfinishlaunch" i have started gps fetching code and started accelemeter.

But i found that once device is kept idle (stopUpdatingLocation) , accelemeter is not getting called. Because of that i cannot detect device movement. Accelemeter callback is not getting called. Here is sample code what i have used:

 

        mMotionManager = [[CMMotionManager alloc] init];

        if (mMotionManager.accelerometerAvailable) {

            mMotionManager.accelerometerUpdateInterval = 1.0/10.0;

           mOperationQueue = [[NSOperationQueue alloc] init];

            [mMotionManager startAccelerometerUpdatesToQueue:mOperationQueuewithHandler:^(CMAccelerometerData *data, NSError *error){

                dispatch_async(dispatch_get_main_queue(), ^{

                    //[self onDeviceMotion];

                    [mAccelerometerReadings addObject:  data];

                    [self updateViewsWithFilteredAcceleration:data.acceleration];

                });

            }];

 

 

Can someone help how to solve this or is this possible to do ?


CLLocationManager,AGPS, GPS
  • 1. Re: Accelemeter is not getting called
    xnav Level 5 Level 5 (6,630 points)

    It seems you're replicating what pausesLocationUpdatesAutomatically does for you.

  • 2. Re: Accelemeter is not getting called
    Kumar007 Level 1 Level 1 (0 points)

    pausesLocationUpdatesAutomatically is it private api ? Can you please explain in detail ?

  • 3. Re: Accelemeter is not getting called
    xnav Level 5 Level 5 (6,630 points)

    From the 6.0 CLLocationManager class Ref

    A Boolean value indicating whether the location manager object may pause location updates.

     

    @property(assign, nonatomic) BOOL pausesLocationUpdatesAutomatically

    Discussion

    Allowing the location manager to pause updates can improve battery life on the target device without sacrificing location data. When this property is set to YES, the location manager pauses updates (and powers down the appropriate hardware) at times when the location data is unlikely to change. For example, if the user stops for food while using a navigation app, the location manager might pause updates for a period of time. You can help the determination of when to pause location updates by assigning a value to the activityType property.

     

    The default value of this property is YES.