Should URLForUbiquityContainerIdentifier: be called in a stream outside the main stream?

I read a lot of conflicting information about whether to call URLForUbiquityContainerIdentifier: outside the main thread or not. In many Apple docs, they always call this method supposedly on the main thread. However, I also read that it is possible that a call to this method may block for a considerable amount of time.

What do everyone think? Call it in the main thread and donโ€™t worry, or yes, ALWAYS this call is called in another thread?

+7
source share
1 answer

NSFileManager can be blocked and it is recommended to start a thread other than the main thread. Here is a snippet of using Grand Central Dispatch to use iCloud Storage in another thread.

 dispatch_queue_t globalQueue = dispatch_get_global_queue(QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(globalQueue, ^{ NSFileManager *fileManager = [[NSFileManager alloc] init]; NSURL *ubiquityContainer = [fileManager URLForUbiquityContainerIdentifier:nil]; dispatch_queue_t mainQueue = dispatch_get_main_queue(); dispatch_async(mainQueue, ^{ [self updateWithUbiquityContainer:ubiquityContainer]; }); }); 

This is from a great article located here:

http://oleb.net/blog/2011/11/ios5-tech-talk-michael-jurewitz-on-icloud-storage/

+6
source

All Articles