NSString *pictureUrl = [[[oneUserDict objectForKey:@"picture"]objectForKey:@"data"]objectForKey:@"url"];
[[AppEngine sharedEngine]imageAtURL:[NSURL URLWithString:pictureUrl] onCompletion:^(UIImage *fetchedImage, NSURL *url, BOOL isInCache)
{
int index = [usersArray indexOfObject:oneUserDict];
NSString *loadName = [NSString stringWithFormat:@"%d of %d",index,[usersArray count]];
NSLog(@"%i",usersArray.count);
int temp=[usersArray count]-10;
if (index!=temp)
{
[[LoadingIndicator currentIndicator]displayActivity:loadName];
NSLog(@"inside loading indicator");
}
else
{
[[LoadingIndicator currentIndicator]displayCompleted:@"Done"];
NSLog(@"finally done");
}
aPerson.image = UIImagePNGRepresentation(fetchedImage);
[appDelegate.managedObjectContext save:nil];
}];
AppEngine is the subclass of MKNetworkEngine
which uses a method called imageAtURL:onCompletion:
what I am currently doing is retrieving all the images from a particular url and and storing them in aPerson.image,basically the above code is in a FOR loop(i.e the for the count of users).
Issues
The above code which is in the completion block never gets executed,i dont know why but i have put a breakpoint inside the block but still the compiler wont run the statements inside the completion block.
Api imageAtURL:onCompletion:
is deprecated. Use imageAtURL:completionHandler:errorHandler:
instead. Also MKNetworkKit provides for UIImageView+MKNetworkKitAdditions
category which provides simple API for image download like setImageFromURL: placeHolderImage:
Cheers!
Amar.