Ios 如何使用并发队列发出异步请求?
有人能帮助我如何使用并发队列发送异步请求吗。大多数讨论似乎都没有得到答案 下面是我编写的代码。提取我的请求时,我的ui显示活动指示器。获取响应后,将显示下一个屏幕Ios 如何使用并发队列发出异步请求?,ios,grand-central-dispatch,Ios,Grand Central Dispatch,有人能帮助我如何使用并发队列发送异步请求吗。大多数讨论似乎都没有得到答案 下面是我编写的代码。提取我的请求时,我的ui显示活动指示器。获取响应后,将显示下一个屏幕 __block NSData *postReply; __block NSDictionary *jsonDict; myQueue = dispatch_queue_create("myQueue", Nil); dispatch_async(myQueue, ^{ [NSURLConnection sendAsy
__block NSData *postReply;
__block NSDictionary *jsonDict;
myQueue = dispatch_queue_create("myQueue", Nil);
dispatch_async(myQueue, ^{
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"%@",request);
jsonDict=(NSDictionary*)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
postReply=data;
dispatch_async(dispatch_get_main_queue(), ^{
if ([[jsonDict objectForKey:@"result"]isEqualToString:@"Success"]) {
UIStoryboard *strObj=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
ViewController1 *v1=[strObj instantiateViewControllerWithIdentifier:@"view1"];
[self presentViewController:v1 animated:YES completion:^{
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
}];
}
});
}];
});
我想这可能会对你有所帮助。你想实现什么目标?什么不起作用?外部调度\u async实际上毫无意义,因为您会立即执行另一个异步请求。在呈现新的视图控制器后停止并移除活动指示器也是oddHi suyash的一个难题。我是一个在iPhone应用程序开发中蹒跚学步的孩子。谢谢。非常感谢您的支持help@MaliniRam你可以找到你的问题的解决方案,也可以不找到。然后,你可以为其他人找到这个答案。
__block NSData *postReply;
__block NSDictionary *jsonDict;
[activityIndicator startAnimating];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"%@",request);
jsonDict=(NSDictionary*)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
postReply=data;
if ([[jsonDict objectForKey:@"result"]isEqualToString:@"Success"]) {
UIStoryboard *strObj=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
ViewController1 *v1=[strObj instantiateViewControllerWithIdentifier:@"view1"];
[self presentViewController:v1 animated:YES completion:^{
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
}];
}
}];