I have to take a screenshot on tapping on "ok" button of UIAlertView. And the screenshot should contain the alertview and all the other views present on the device screen. I tried to implement the functionality of screenshot capturing using below code. But the screenshot that I have taken is giving a blank image. Please give a solution for this issue.
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow] ;
CGRect rect = CGRectMake(0, 64, 1024, 704);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, -rect.origin.x, -rect.origin.y);
[keyWindow.rootViewController.view drawViewHierarchyInRect:keyWindow.rootViewController.view.bounds afterScreenUpdates:YES];
UIImage *screenShotImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *myImageData = UIImagePNGRepresentation(screenShotImage);
[fileManager createFileAtPath:@"/Users/mac/Desktop/myimage.png" contents:myImageData attributes:nil];