How do some Apple API functions implement calling callback blocks on specific queues depending on the calling queue?
For example, when calling the [ALAssetsLibrary enumerateGroupsWithTypes:usingBlock:failureBlock:] function from the main queue, the result block is also called on the main queue, while when calling this function from a global/background queue or a custom queue, the result block is called on the default priority global queue (com.apple.root.default-qos).
Obviously, the dispatch_get_current_queue() function could do the job, but that function is deprecated since iOS6.
Example code below:
dispatch_async(dispatch_get_main_queue(), ^{
ALAssetsLibrary *library = [ALAssetsLibrary new];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
NSLog(@"%@", group); //gets called on main queue
} failureBlock: nil];
});
dispatch_async(dispatch_queue_create("queue", DISPATCH_QUEUE_SERIAL), ^{
ALAssetsLibrary *library = [ALAssetsLibrary new];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
NSLog(@"%@", group); //gets called on com.apple.root.default-qos queue
} failureBlock: nil];
});