문제

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?

도움이 되었습니까?

해결책

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top