URLForUbiquityContainerIdentifier应该在主线程之外的线程中调用吗? [英] Should URLForUbiquityContainerIdentifier: be called in a thread outside the main thread?

查看:459
本文介绍了URLForUbiquityContainerIdentifier应该在主线程之外的线程中调用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多有关 URLForUbiquityContainerIdentifier:是否应该在主线程外调用的相互矛盾的信息。在很多Apple的文档中,他们总是在主线程上调用这个方法。但是,我也读过,调用这种方法可能会阻塞很长时间。

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?

推荐答案

NSFileManager可以是阻塞并建议在与主线程不同的线程上运行。以下是使用Grand Central Dispatch在不同线程上使用iCloud Storage的片段

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 /

这篇关于URLForUbiquityContainerIdentifier应该在主线程之外的线程中调用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆