Skip to content

Instantly share code, notes, and snippets.

@JaniJegoroff
Last active August 29, 2015 14:08
Show Gist options
  • Save JaniJegoroff/fef4dc983780f2797dae to your computer and use it in GitHub Desktop.
Save JaniJegoroff/fef4dc983780f2797dae to your computer and use it in GitHub Desktop.
Calabash backdoor method to capture screenshot and save it to Photos
- (NSString *)takeScreenShot:(NSString *)aIgnore
{
UIViewController* viewController = (UIViewController*) self.window.rootViewController;
UIGraphicsBeginImageContextWithOptions(viewController.view.bounds.size, viewController.view.opaque, 0.0);
[viewController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:@"shot.PNG" atomically:YES];
UIImageWriteToSavedPhotosAlbum(image, nil, NULL, NULL);
return @"true";
}
irb(main):005:0> backdoor('takeScreenShot', '')
"true"
http://www.screencast.com/t/jsm9x8Z9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment