![](/img/trans.png)
[英]Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread
[英]Should URLForUbiquityContainerIdentifier: be called in a thread outside the main thread?
我已经阅读了很多有关URLForUbiquityContainerIdentifier:
是否应在主线程之外调用的信息。 在Apple的许多文档中,他们通常总是在主线程上调用此方法。 但是,我还读到,调用此方法可能会阻塞很长时间。
每个人的想法是什么? 在主线程中调用它,不用担心或可以,总是在另一个线程中进行此调用吗?
NSFileManager可能会阻塞,建议在与主线程不同的线程上运行。 这是使用Grand Central Dispatch在不同线程上利用iCloud存储的摘要
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/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.