URLForUbiquityContainerIdentifier: 应该在主线程之外的线程中调用吗?

Should URLForUbiquityContainerIdentifier: be called in a thread outside the main thread?(URLForUbiquityContainerIdentifier: 应该在主线程之外的线程中调用吗?)
本文介绍了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: 应该在主线程之外的线程中调用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Resume game cocos2d(恢复游戏 cocos2d)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)