【问题标题】:Should URLForUbiquityContainerIdentifier: be called in a thread outside the main thread?URLForUbiquityContainerIdentifier: 应该在主线程之外的线程中调用吗?
【发布时间】:2012-02-21 10:47:19
【问题描述】:

我已经阅读了很多关于是否应该在主线程之外调用URLForUbiquityContainerIdentifier: 的相互矛盾的信息。在许多 Apple 的文档中,他们总是大概在主线程上调用此方法。但是,我还了解到调用此方法可能会阻塞很长时间。

大家的想法是什么?在主线程中调用它,不用担心,或者是的,总是在另一个线程中调用它?

【问题讨论】:

    标签: iphone objective-c ios ios5 icloud


    【解决方案1】:

    NSFileManager 可能会阻塞,建议在与主线程不同的线程上运行。这是使用 Grand Central Dispatch 在不同线程上利用 iCloud Storage 的 sn-p

    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];
        });
    });
    

    这是来自这里的一篇很棒的文章:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-04
      • 2014-03-09
      • 1970-01-01
      • 2020-04-25
      • 2011-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多