Merge branch 'release-3.0.0'

This commit is contained in:
StefanoMagrassi 2016-01-22 15:38:43 +01:00
commit 247413e97d
5 changed files with 64 additions and 51 deletions

View File

@ -1,16 +1,25 @@
# 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).
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
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).
## Alerts
### 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.
### 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
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
#### `cordova.base64ToGallery(data, [prefix, success, fail])`

View File

@ -1,6 +1,6 @@
{
"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",
"license": "MIT",
"scripts": {

View File

@ -1,8 +1,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>
<engine name="cordova-ios" version="<3.8.0" />
<engine name="cordova-ios" version=">=3.8.0" />
</engines>
<name>base64ToGallery</name>

View File

@ -2,20 +2,25 @@
// Base64ToGallery.h
// Base64ToGallery PhoneGap/Cordova plugin
//
// Created by Tommy-Carlos Williams on 29/03/12.
// Copyright (c) 2012 Tommy-Carlos Williams. All rights reserved.
// Copyright (c) 2016 StefanoMagrassi <stefano.magrassi@gmail.com>
//
// Based on Tommy-Carlos Williams "Canvas2ImagePlugin.h"
//
// MIT Licensed
//
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDV.h>
@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

View File

@ -2,8 +2,10 @@
// Base64ToGallery.m
// Base64ToGallery PhoneGap/Cordova plugin
//
// Created by Tommy-Carlos Williams on 29/03/12.
// Copyright (c) 2012 Tommy-Carlos Williams. All rights reserved.
// Copyright (c) 2016 StefanoMagrassi <stefano.magrassi@gmail.com>
//
// Based on Tommy-Carlos Williams "Canvas2ImagePlugin.m"
//
// MIT Licensed
//
@ -11,49 +13,46 @@
#import <Cordova/CDV.h>
@implementation Base64ToGallery
@synthesize callbackId;
//-(CDVPlugin*) initWithWebView:(UIWebView*)theWebView
//{
// self = (Base64ToGallery*)[super initWithWebView:theWebView];
// return self;
//}
- (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command
{
[self.commandDelegate runInBackground:^{
self.callbackId = command.callbackId;
self.result = nil;
- (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command
{
self.callbackId = command.callbackId;
NSData* imageData = [NSData dataFromBase64String:[command.arguments objectAtIndex:0]];
NSString* base64String = [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
{
CDVPluginResult* result = nil;
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
// Was there an error?
if (error != NULL) {
NSLog(@"ERROR: %@", error);
} else {
self.result = [CDVPluginResult resultWithStatus:CDVCommandStatus_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
{
[callbackId release];
[super dealloc];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
// With errors
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