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?

Était-ce utile?

La 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];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top