Monday 28 July 2014

How to take screenshot programmatically in iOS SDK

/// first import

#import <QuartzCore/QuartzCore.h>

//// then  user this code to save images

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])

    UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);

else

    UIGraphicsBeginImageContext(self.window.bounds.size);

[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

NSData * data = UIImagePNGRepresentation(image);

[data writeToFile:@"foo.png" atomically:YES];




thanks to Saurabh Sharma

http://www.makebetterthings.com/iphone/how-to-take-screenshot-programmatically-in-ios-sdk/