Skip to content

Instantly share code, notes, and snippets.

@stith
Created December 14, 2011 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stith/1475372 to your computer and use it in GitHub Desktop.
Save stith/1475372 to your computer and use it in GitHub Desktop.
NSString *filename = [NSString stringWithFormat:@"%0.0f.png", [[NSDate date] timeIntervalSince1970]];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
MSLogTo(@"info", @"documentsPath = %@",documentsPath);
NSURL *newUrl = [NSURL fileURLWithPath:documentsPath isDirectory:YES];
NSString *saveTo = [[newUrl absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
MSLogTo(@"info", @"Saving image to %@",saveTo);
NSError *error;
if (![UIImagePNGRepresentation(image) writeToFile:saveTo options:NSDataWritingAtomic error:&error]) {
MSLogTo(@"errors",@"Couldn't save image to documents: %@ <%@>",error,[error localizedDescription]);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment