6 Commits

Author SHA1 Message Date
StefanoMagrassi 247413e97d Merge branch 'release-3.0.0' 2016-01-22 15:38:43 +01:00
StefanoMagrassi 9c482f9782 version 3.0.0 - fixes #3 2016-01-22 15:36:21 +01:00
StefanoMagrassi 2495048e3b Merge branch 'readme_updates' into issue#3 2016-01-22 15:32:39 +01:00
StefanoMagrassi 1384a7d8c1 readme updates for version 3.0.0 2016-01-22 15:32:26 +01:00
StefanoMagrassi 6152a9fcd2 edited to be compliant with cordova-ios > 3.8.0
- removed iVars in Base64ToGallery interface definition (compiler warning)
- callbackId and result class public property
- fixed wrong variables refencies and names
- background thread (previous commit, but it's important to notice it)
2016-01-21 12:18:17 +01:00
StefanoMagrassi 538f749c1b changed ios api 2016-01-21 11:20:50 +01:00
5 changed files with 64 additions and 51 deletions
+13 -4
View File
@@ -1,16 +1,25 @@
# Cordova base64ToGallery Plugin # Cordova base64ToGallery Plugin
This plugin (based on [devgeeks/Canvas2ImagePlugin](http://github.com/devgeeks/Canvas2ImagePlugin)) allows you to save base64 data as a png image into the device (iOS Photo Library, Android Gallery or WindowsPhone 8 Photo Album). This plugin (based on [devgeeks/Canvas2ImagePlugin](http://github.com/devgeeks/Canvas2ImagePlugin)) allows you to save base64 data as a png image into the device (iOS Photo Library, Android Gallery or WindowsPhone 8 Photo Album).
The plugin is a kind of fork of the [solderzzc/Base64ImageSaverPlugin](https://github.com/solderzzc/Base64ImageSaverPlugin) but with a cleaner history (a.k.a: no tags from Canvas2ImagePlugin repo). The plugin is a kind of fork of the [solderzzc/Base64ImageSaverPlugin](https://github.com/solderzzc/Base64ImageSaverPlugin) but with a cleaner history (a.k.a: no tags from Canvas2ImagePlugin repo) and a newer iOS implementation.
## Alert ## Alerts
In order to be more consistent with the cordova naming convention, since version 2.0 the repository name and the cordova plugin id have changed to **cordova-base64-to-gallery** (issue #1).
### Plugin id - [issue #1](https://github.com/Nexxa/cordova-base64-to-gallery/issues/1)
In order to be more consistent with the cordova naming convention, since version 2.0 the repository name and the cordova plugin id have changed to **cordova-base64-to-gallery**.
Please uninstall the old version and reinstall the new one. Please uninstall the old version and reinstall the new one.
### cordova-ios > 3.8.0 - [issue #3](https://github.com/Nexxa/cordova-base64-to-gallery/issues/3)
According to the [documentation](https://github.com/apache/cordova-ios/blob/master/guides/API%20changes%20in%204.0.md#nsdatabase64h-removed), `NSData+Base64.h` class was removed starting from version 4.0.0 of the **cordova-ios platform** (and it was already deprecated from version 3.8.0).
So, cordova-base64-to-gallery plugin **from version 3.0.0** has changed the iOS implementation in order to support the changes in cordova-ios platform.
If you need to support cordova-ios < 3.8.0 please refer to [cordova-base64-to-gallery@2.0.2](https://github.com/Nexxa/cordova-base64-to-gallery/tree/2.0.2). There is also an "**old**" branch that might have some updates in the future (Android/WP8 fixes or something like that).
## Usage ## Usage
Call the `cordova.base64ToGallery()` method using success and error callbacks and the id attribute or the element object of the canvas to save: Call the `cordova.base64ToGallery()` method using success and error callbacks and the id attribute or the element object of the canvas to save (`prefix` is optional):
### Methods ### Methods
#### `cordova.base64ToGallery(data, [prefix, success, fail])` #### `cordova.base64ToGallery(data, [prefix, success, fail])`
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "cordova-base64-to-gallery", "name": "cordova-base64-to-gallery",
"version": "2.0.2", "version": "3.0.0",
"description": "Cordova plugin to save base64 data as a png image into the device", "description": "Cordova plugin to save base64 data as a png image into the device",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
+2 -2
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns:android="http://schemas.android.com/apk/res/android" xmlns="http://www.phonegap.com/ns/plugins/1.0" id="cordova-base64-to-gallery" version="2.0.2"> <plugin xmlns:android="http://schemas.android.com/apk/res/android" xmlns="http://www.phonegap.com/ns/plugins/1.0" id="cordova-base64-to-gallery" version="3.0.0">
<engines> <engines>
<engine name="cordova-ios" version="<3.8.0" /> <engine name="cordova-ios" version=">=3.8.0" />
</engines> </engines>
<name>base64ToGallery</name> <name>base64ToGallery</name>
+13 -8
View File
@@ -2,20 +2,25 @@
// Base64ToGallery.h // Base64ToGallery.h
// Base64ToGallery PhoneGap/Cordova plugin // Base64ToGallery PhoneGap/Cordova plugin
// //
// Created by Tommy-Carlos Williams on 29/03/12. // Copyright (c) 2016 StefanoMagrassi <stefano.magrassi@gmail.com>
// Copyright (c) 2012 Tommy-Carlos Williams. All rights reserved. //
// Based on Tommy-Carlos Williams "Canvas2ImagePlugin.h"
//
// MIT Licensed // MIT Licensed
// //
#import <Cordova/CDVPlugin.h> #import <Cordova/CDV.h>
@interface Base64ToGallery : CDVPlugin @interface Base64ToGallery : CDVPlugin
{
NSString* callbackId;
}
@property (nonatomic, copy) NSString* callbackId; //{
// NSString* callbackId;
// CDVPluginResult* result;
//}
- (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command; @property (nonatomic, copy) NSString* callbackId;
@property (nonatomic, assign) CDVPluginResult* result;
- (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command;
@end @end
+35 -36
View File
@@ -2,8 +2,10 @@
// Base64ToGallery.m // Base64ToGallery.m
// Base64ToGallery PhoneGap/Cordova plugin // Base64ToGallery PhoneGap/Cordova plugin
// //
// Created by Tommy-Carlos Williams on 29/03/12. // Copyright (c) 2016 StefanoMagrassi <stefano.magrassi@gmail.com>
// Copyright (c) 2012 Tommy-Carlos Williams. All rights reserved. //
// Based on Tommy-Carlos Williams "Canvas2ImagePlugin.m"
//
// MIT Licensed // MIT Licensed
// //
@@ -11,49 +13,46 @@
#import <Cordova/CDV.h> #import <Cordova/CDV.h>
@implementation Base64ToGallery @implementation Base64ToGallery
@synthesize callbackId;
//-(CDVPlugin*) initWithWebView:(UIWebView*)theWebView - (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command
//{ {
// self = (Base64ToGallery*)[super initWithWebView:theWebView]; [self.commandDelegate runInBackground:^{
// return self; self.callbackId = command.callbackId;
//} self.result = nil;
- (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command NSString* base64String = [command.arguments objectAtIndex:0];
{
self.callbackId = command.callbackId;
NSData* imageData = [NSData dataFromBase64String:[command.arguments objectAtIndex:0]];
UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease]; if (base64String != nil && [base64String length] > 0) {
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); NSData* imageData = [[[NSData alloc] initWithBase64EncodedString:base64String options:0] autorelease];
} UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease];
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
{
CDVPluginResult* result = nil;
// Was there an error? } else {
if (error != NULL) { self.result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
NSLog(@"ERROR: %@", error);
result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description]; [self.commandDelegate sendPluginResult:self.result callbackId:self.callbackId];
}
[self.webView stringByEvaluatingJavaScriptFromString:[result toErrorCallbackString: self.callbackId]]; }];
// No errors
} else {
result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
[self.webView stringByEvaluatingJavaScriptFromString:[result toSuccessCallbackString: self.callbackId]];
} }
}
- (void)dealloc - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{ {
[callbackId release]; // With errors
[super dealloc]; if (error != NULL) {
} NSLog(@"ERROR: %@", error);
self.result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description];
// No errors
} else {
self.result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
}
[self.commandDelegate sendPluginResult:self.result callbackId:self.callbackId];
}
@end @end