Created
August 16, 2015 06:47
-
-
Save ptmt/17a92409354da1d4915b to your computer and use it in GitHub Desktop.
Taking screenshot on react-native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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