我正在尝试通过加载对象集合RestKit
并发现此操作阻塞了主线程。UIViewController
具体来说,当消息中出现a 时会调用此功能-(void)viewDidAppear:(BOOL)animated;
。只要请求正在加载,用户就无法与 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