Skip to content

Instantly share code, notes, and snippets.

@ptmt
Created August 16, 2015 06:47
Show Gist options
  • Save ptmt/17a92409354da1d4915b to your computer and use it in GitHub Desktop.
Save ptmt/17a92409354da1d4915b to your computer and use it in GitHub Desktop.
Taking screenshot on react-native
- (NSURL *) takeScreenshot:(NSString *)imageName {
UIViewController *root = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
UIGraphicsBeginImageContextWithOptions(root.view.bounds.size, NO, [UIScreen mainScreen].scale);
[root.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
NSData *imgData = UIImagePNGRepresentation(image);
UIGraphicsEndImageContext();
NSString *filePath = [NSString stringWithFormat:@"%@%@.png", NSTemporaryDirectory(), imageName];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
[imgData writeToFile:filePath atomically:YES];
return fileURL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment