Search code examples
iphoneobjective-ciosmultithreadingaccelerometer

Using a serial queue with CMMotionManager


Im using the the startAccelerometerUpdatesToQueue: withHandler: method of CMMotionManager to get accelerometer updates and I'm creating the queue in line this is my line of code

[self.motionManager startAccelerometerUpdatesToQueue:[[[NSOperationQueue alloc] init] autorelease] withHandler:^(CMAccelerometerData *data, NSError *error)

I'm not sure but from my debugging NSOperationQueue seems to create a Concurrent queue but I need a serial queue so that the blocks are executed one at a time so I would like to make create a serial queue I tried using dispatch_queue_create method but I couldn't use it in line like I was using NSOperationQueue.

Is there a way I can do it in line? If not where can I create my queue?


Solution

  • After further research I found out that NSOperationQueue and dispatch_queue_create are 2 completely different things and you have to use NSOperationQueue with startAccelerometerUpdatesToQueue: withHandler:

    To make this Queue serial I used [NameQueue setMaxConcurrentOperationCount:1]; this makes it a max of 1 tread running at the one time.