Skip to content

Instantly share code, notes, and snippets.

@gabrielecirulli
Created April 12, 2014 21:30
Show Gist options
  • Save gabrielecirulli/884f79e668401d5dc7d5 to your computer and use it in GitHub Desktop.
Save gabrielecirulli/884f79e668401d5dc7d5 to your computer and use it in GitHub Desktop.
--- a/src/ios/Screenshot.m
+++ b/src/ios/Screenshot.m
@@ -11,6 +11,7 @@
#import <Cordova/CDV.h>
#import "Screenshot.h"
+#import "AssetsLibrary/AssetsLibrary.h";
@implementation Screenshot
@@ -25,7 +26,7 @@
// statusBarOrientation is more reliable than UIDevice.orientation
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
- if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
+ if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
// landscape check
imageRect = CGRectMake(0, 0, CGRectGetHeight(screenRect), CGRectGetWidth(screenRect));
} else {
@@ -48,7 +49,19 @@
[webView.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
- UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
+
+ ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
+
+ // Request to save the image to camera roll
+ [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation]
+ if (error) {
+ // The callback should receive the error
+ } else {
+ // The callback should receive the response json object with the path
+ }
+ }];
+ [library release];
+
UIGraphicsEndImageContext();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment