問(wèn)題描述
我已經(jīng)閱讀了很多關(guān)于是否應(yīng)該在主線程之外調(diào)用 URLForUbiquityContainerIdentifier:
的相互矛盾的信息.在許多 Apple 的文檔中,他們總是大概在主線程上調(diào)用此方法.但是,我還了解到調(diào)用此方法可能會(huì)阻塞很長(zhǎng)時(shí)間.
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.
大家的想法是什么?在主線程中調(diào)用它,不用擔(dān)心,或者是的,總是在另一個(gè)線程中調(diào)用它?
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 可能會(huì)阻塞,建議在與主線程不同的線程上運(yùn)行.這是使用 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];
});
});
這是來(lái)自這里的一篇很棒的文章:
This is from a great article located here:
http://oleb.net/blog/2011/11/ios5-tech-talk-michael-jurewitz-on-icloud-storage/
這篇關(guān)于URLForUbiquityContainerIdentifier: 應(yīng)該在主線程之外的線程中調(diào)用嗎?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!