Im trying to create a image gallery using UICollectionView. But the dispatch_queue does not seem to download image instead it skips the download and continues executing the next statement.
Below is my code:
for(int i=0;i<[_urlArray count];i++){
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0), ^{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[_urlArray objectAtIndex:i]]];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
path = [path stringByAppendingString:[NSString stringWithFormat:@"%d.png",i]];
NSLog(@"img data %@",data);
[data writeToFile:path atomically:YES];
UIImage *theImage=[UIImage imageNamed:path];
[_imgArray addObject:theImage];
dispatch_async(dispatch_get_main_queue(), ^{
});
});
}
I even tried AFNetworking and SDWebImage. But did not help me. Please help me with this. Thank you.