To expand Brentโs answer, the following code will capture a screenshot and save it in the Documents folder as a PNG named screenshot.png:
UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow]; UIGraphicsBeginImageContext(screenWindow.frame.size); [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSData *screenshotPNG = UIImagePNGRepresentation(screenshot); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSError *error = nil; [screenshotPNG writeToFile:[documentsDirectory stringByAppendingPathComponent:@"screenshot.png"] options:NSAtomicWrite error:&error];
This is a little rude since it will leave a blank space at the top of the screen for the title and will not grab content from CAEAGLLayers.
Also, I donโt think you can use the standard mailto: // URL construct, and then openURL, to send nested MIME attachments. Maybe the 3.0 SDK fixes this, but I still have to play with it. You may need to use something like sksmtpmessage to send a message directly from your application.
Brad larson
source share