-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathCanvas2ImagePlugin.m
More file actions
54 lines (46 loc) · 1.86 KB
/
Canvas2ImagePlugin.m
File metadata and controls
54 lines (46 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Canvas2ImagePlugin.m
// Canvas2ImagePlugin PhoneGap/Cordova plugin
//
// Created by Tommy-Carlos Williams on 29/03/12.
// Copyright (c) 2012 Tommy-Carlos Williams. All rights reserved.
// MIT Licensed
//
#import "Canvas2ImagePlugin.h"
#import <Cordova/CDV.h>
#import <AssetsLibrary/AssetsLibrary.h>
@implementation Canvas2ImagePlugin
@synthesize callbackId;
//-(CDVPlugin*) initWithWebView:(UIWebView*)theWebView
//{
// self = (Canvas2ImagePlugin*)[super initWithWebView:theWebView];
// return self;
//}
- (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command
{
self.callbackId = command.callbackId;
NSData* imageData = [[NSData alloc] initWithBase64EncodedString:[command.arguments objectAtIndex:0] options:0];
UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Request to save the image to camera roll
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation:ALAssetOrientationRight /*(ALAssetOrientation)[image imageOrientation]*/ completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
// Show error message...
NSLog(@"ERROR: %@",error);
CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description];
[self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
} else {
// Show message image successfully saved
NSLog(@"IMAGE SAVED!");
CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString: [assetURL absoluteString]];
[self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
}
}];
[library release];
}
- (void)dealloc
{
[callbackId release];
[super dealloc];
}
@end