Last active
January 4, 2016 01:19
-
-
Save DaveBatton/8547787 to your computer and use it in GitHub Desktop.
Saves any images found in the specified view or any of its subviews. Images are saved in the application's Documents directory.
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
- (void)stealImagesFromView:(UIView *)view | |
{ | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder | |
for (UIView *subview in view.subviews) { | |
if ([subview isKindOfClass:[UIImageView class]]) { | |
UIImageView *imageView = (UIImageView *)subview; | |
if (imageView.image) { | |
NSString *filename = [NSString stringWithFormat:@"image (%f)", [NSDate timeIntervalSinceReferenceDate]]; | |
filename = [filename stringByAppendingPathExtension:@"png"]; | |
NSString *path = [documentsDirectory stringByAppendingPathComponent:filename]; | |
NSData *imageData = UIImagePNGRepresentation(imageView.image); | |
[imageData writeToFile:path atomically:YES]; | |
} | |
} | |
[self stealImagesFromView:subview]; | |
} | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
NSLog(@"Stolen images can be found here: %@", documentsDirectory); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment