Question

I am using CoreMotion in my app to use Accelerometer. I'm doing fine but how can i stop my accelerometer to receive motion update?

Was it helpful?

Solution

Did you try this?

CMMotionManager *motionManager = [CMMotionManager sharedInstance];
[motionManager 
     startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc] init]
     withHandler:^(CMAccelerometerData *data, NSError *error)
     {

         dispatch_async(dispatch_get_main_queue(),
                        ^{
                        NSLog(@"hello");
                            [motionManager stopAccelerometerUpdates];
                        });   

     }];

Or using notification,

[[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(stopAccelerometer)
                                          name:UIApplicationDidEnterBackgroundNotification 
                                        object:nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top