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

北慕城南 提交于 2019-11-30 15:22:47

问题


I've read a lot of conflicting information about whether or not URLForUbiquityContainerIdentifier: should be called outside the main thread or not. In a lot of Apple's documentation they always call this method presumably on the main thread. However, I've also read that it's possible that calling this method could block for a significant time.

What is everyone's thoughts? Call it in the main thread and don't worry or yes, ALWAYS make this call in another thread?


回答1:


NSFileManager can be blocking and is recommended to run on a different thread than the main thread. Here is a snippet of using Grand Central Dispatch to utilize iCloud Storage on a different 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/



来源:https://stackoverflow.com/questions/9050359/should-urlforubiquitycontaineridentifier-be-called-in-a-thread-outside-the-main

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!