我試圖通過RestKit
加載對象的集合,並且發現這個操作阻塞了主線程。特別是,當-(void)viewDidAppear:(BOOL)animated;
消息中出現UIViewController
時,會調用此功能。只要加載請求,用戶就無法與UI進行交互,並且必須等待操作完成。iOS:RestKit入隊管理對象操作阻止UI線程
如何指示RestKit異步執行請求(我認爲它已經是)並停止阻塞主線程?
-(void)rtrvArtistsByStudio:(ISStudio *)studio
{
NSLog(@"Retrieving Artists for studio %ld", [studio studioID]);
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
NSDictionary *params = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%ld", [studio studioID]] forKey:@"studioID"];
NSURLRequest *request = [restkit requestWithObject:nil method:RKRequestMethodGET path:@"/restAPI/rtrvArtistsByStudio" parameters:params];
RKManagedObjectRequestOperation *operation = [restkit managedObjectRequestOperationWithRequest:request managedObjectContext:restkit.managedObjectStore.persistentStoreManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSArray *artists = [mappingResult array];
[studio setArtists:artists];
[notificationCenter postNotificationName:nStudioLoadedArtists object:studio];
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Failed to load artists for studio %ld due to %@", [studio studioID], error);
[notificationCenter postNotificationName:nStudioFailedLoadingArtists object:studio];
}];
[restkit enqueueObjectRequestOperation:operation];
}
編輯: 我也應該注意到,restkit
是一個指向RKObjectManager
一個實例。
RestKit版本是0.20
您正在運行哪個版本的RestKit? – Alex
0.20.0,編輯並添加到原始問題。 – kz3