I have two NSIvocationOperations in one NSOperationQueue. And I used setQueuePriority to adjust the execution order of two operations: 1-> 2 or 2-> 1. However, the code worked on the emulator, but failed on my iPhone.
My code looks like this:
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init]; operationQueue.maxConcurrentOperationCount = 1; NSInvocationOperation *operation1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(thread1) object:nil]; [operation1 setQueuePriority:NSOperationQueuePriorityVeryLow]; NSInvocationOperation *operation2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(thread2) object:nil]; [operation2 setQueuePriority:NSOperationQueuePriorityHigh]; [operationQueue addOperation:operation1]; [operationQueue addOperation:operation2];
Operation2 must be performed before operation1, and I saw the same result on the emulator. While on iPhone, operation1 was always performed first, regardless of how I adjusted their QueuePriorities. Why is this so?
frank19900731
source share