diff options
| author | PliablePixels <pliablepixels@gmail.com> | 2015-07-15 21:02:53 -0400 |
|---|---|---|
| committer | PliablePixels <pliablepixels@gmail.com> | 2015-07-15 21:02:53 -0400 |
| commit | 03d5e38520e1779b807af95187782a27155372c8 (patch) | |
| tree | a8feca72bb30113ca5c231fdb10f362f47b9a79d /plugins/org.devgeeks.Canvas2ImagePlugin/src/ios | |
| parent | 3dbe41f90b5e7058ec0fb5460516812143d4f254 (diff) | |
added plugin for save to camera roll
Diffstat (limited to 'plugins/org.devgeeks.Canvas2ImagePlugin/src/ios')
| -rw-r--r-- | plugins/org.devgeeks.Canvas2ImagePlugin/src/ios/Canvas2ImagePlugin.h | 22 | ||||
| -rw-r--r-- | plugins/org.devgeeks.Canvas2ImagePlugin/src/ios/Canvas2ImagePlugin.m | 58 |
2 files changed, 80 insertions, 0 deletions
diff --git a/plugins/org.devgeeks.Canvas2ImagePlugin/src/ios/Canvas2ImagePlugin.h b/plugins/org.devgeeks.Canvas2ImagePlugin/src/ios/Canvas2ImagePlugin.h new file mode 100644 index 00000000..ef7bc567 --- /dev/null +++ b/plugins/org.devgeeks.Canvas2ImagePlugin/src/ios/Canvas2ImagePlugin.h @@ -0,0 +1,22 @@ +// +// Canvas2ImagePlugin.h +// 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 <Cordova/CDVPlugin.h> + +@interface Canvas2ImagePlugin : CDVPlugin +{ + NSString* callbackId; +} + +@property (nonatomic, copy) NSString* callbackId; + +- (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command; + +@end diff --git a/plugins/org.devgeeks.Canvas2ImagePlugin/src/ios/Canvas2ImagePlugin.m b/plugins/org.devgeeks.Canvas2ImagePlugin/src/ios/Canvas2ImagePlugin.m new file mode 100644 index 00000000..734ee006 --- /dev/null +++ b/plugins/org.devgeeks.Canvas2ImagePlugin/src/ios/Canvas2ImagePlugin.m @@ -0,0 +1,58 @@ +// +// 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> + +@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 dataFromBase64String:[command.arguments objectAtIndex:0]]; + + UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease]; + UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); + +} + +- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo +{ + // Was there an error? + if (error != NULL) + { + // Show error message... + NSLog(@"ERROR: %@",error); + CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description]; + [self.webView stringByEvaluatingJavaScriptFromString:[result toErrorCallbackString: self.callbackId]]; + } + else // No errors + { + // Show message image successfully saved + NSLog(@"IMAGE SAVED!"); + CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString:@"Image saved"]; + [self.webView stringByEvaluatingJavaScriptFromString:[result toSuccessCallbackString: self.callbackId]]; + } +} + +- (void)dealloc +{ + [callbackId release]; + [super dealloc]; +} + + +@end |
