2012-01-29 17 views
7

He leído mucha información contradictoria sobre si se debe llamar o no al URLForUbiquityContainerIdentifier: fuera del hilo principal o no. En gran parte de la documentación de Apple, siempre llaman a este método, presumiblemente, en el hilo principal. Sin embargo, también he leído que es posible que llamar a este método pueda bloquearse durante un tiempo significativo.¿Debería invocarse URLForUbiquityContainerIdentifier en un hilo fuera del hilo principal?

¿Cuál es la opinión de todos? Llámalo en el hilo principal y no te preocupes o sí, ¿SIEMPRE haces esta llamada en otro hilo?

Respuesta

6

NSFileManager puede estar bloqueando y se recomienda ejecutar en un subproceso diferente del subproceso principal. Aquí hay un fragmento de la utilización de Grand Central Dispatch para utilizar iCloud Storage en un subproceso diferente

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

Se trata de un gran artículo que se encuentre aquí:

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

Cuestiones relacionadas