Hello!
I've been working on an IOS app that uses the Scaleform Mobile SDK as the rendering backend for a game made entirely in flash. I've been tasked with implimenting a button as part of the game interface that will take a screenshot and save it to the camera roll. I was able to get this working on any device running IOS 7.0 or higher using the following code:
//This works on ios 7 and above
NSLog(@"Saving screenshot...");
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, [UIScreenmainScreen].scale);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
When I try and run this code on a device running IOS 6.0 or fewer the app will crash. Specifically it crashes on this line:
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:NO];
XCode is throwing a NSInvalidArgumentException saying unrecognized selector sent to instance. I've done a bit of research and I should be able to use the following code to take a screenshot on older versions of IOS; however it only saves out a blank white screenshot.
//This works on all things but it saves a white screenshot.
CGSize imageSize = CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height);
UIGraphicsBeginImageContextWithOptions(imageSize, YES, 1.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
If anyone knows of a way to make this work I would greatly appreciate it.