Call the scaling method in the background thread like this :
if ((imageData.length/1024) >= 1024) {
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.dimBackground = YES;
HUD.labelText = NSLocalizedString(@"HUDHomeLoadingTableData", @"Home View Controller - Loading Table Data");
HUD.removeFromSuperViewOnHide = YES;
self.scaledImageData = imageData;
[self performSelectorInBackground:@selector(scaleDown:) withObject:imageData];
}
-(void)scaleDown:(NSData*)imageData
{
while ((imageData.length/1024) >= 1024) {
NSLog(@"While start - The imagedata size is currently: %f KB",roundf((imageData.length/1024)));
// While the imageData is too large scale down the image
// Get the current image size
CGSize currentSize = CGSizeMake(image.size.width, image.size.height);
// Resize the image
image = [image resizedImage:CGSizeMake(roundf(((currentSize.width/100)*80)), roundf(((currentSize.height/100)*80))) interpolationQuality:kMESImageQuality];
// Pass the NSData out again
self.scaledImageData = UIImageJPEGRepresentation(image, kMESImageQuality);
}
//hide the hud on main thread
[self performSelectorOnMainThread:@selector(hideHUD) withObject:nil waitUntilDone:NO];
}
-(void)hideHUD
{
[self.HUD hide:YES];
}