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

前端 未结 1 1052
没有蜡笔的小新
没有蜡笔的小新 2021-01-02 15:07

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 o

相关标签:
1条回答
  • 2021-01-02 15:44

    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/

    0 讨论(0)
提交回复
热议问题