15 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
StefanoMagrassi b26b55a061 Merge branch 'release-2.0.2' 2016-01-20 18:01:10 +01:00
StefanoMagrassi bac8ff71a3 version 2.0.2 2016-01-20 18:00:59 +01:00
StefanoMagrassi ed8a8f13d3 Merge branch 'update-version-script' 2016-01-20 17:58:34 +01:00
StefanoMagrassi 3d740e8e63 removed libxmljs and back to good ol' regex 2016-01-20 17:58:18 +01:00
StefanoMagrassi 1eb312609c Merge branch 'hotfix-gitignore' 2016-01-20 17:06:23 +01:00
StefanoMagrassi ce3f8563c4 .log ignored 2016-01-20 17:06:13 +01:00
StefanoMagrassi 59998f3950 Merge branch 'plugin-engine-conf' 2016-01-20 17:02:20 +01:00
StefanoMagrassi e4dfa52b05 .npmignore - leaner module 2016-01-20 17:01:25 +01:00
StefanoMagrassi 4080c64451 cordova-ios platform version
It was specified the supported version of cordova-ios platform
2016-01-20 16:59:01 +01:00
8 changed files with 97 additions and 65 deletions
+1
View File
@@ -1,5 +1,6 @@
# Commons # Commons
/node_modules /node_modules
*.log
# OS # OS
.DS_Store .DS_Store
+5
View File
@@ -0,0 +1,5 @@
# Make NPM module leaner
/scripts
.eslintrc
.npmrc
+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])`
+3 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "cordova-base64-to-gallery", "name": "cordova-base64-to-gallery",
"version": "2.0.1", "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": {
@@ -37,6 +37,7 @@
"base64", "base64",
"save", "save",
"photo library", "photo library",
"gallery",
"ecosystem:cordova", "ecosystem:cordova",
"cordova-ios", "cordova-ios",
"cordova-android", "cordova-android",
@@ -56,6 +57,6 @@
], ],
"devDependencies": { "devDependencies": {
"eslint": "1.10.3", "eslint": "1.10.3",
"libxmljs": "0.16.1" "nodemsg": "1.0.0"
} }
} }
+10 -8
View File
@@ -1,5 +1,9 @@
<?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.1"> <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" />
</engines>
<name>base64ToGallery</name> <name>base64ToGallery</name>
@@ -17,6 +21,8 @@
<!-- ios --> <!-- ios -->
<platform name="ios"> <platform name="ios">
<source-file compiler-flags="-fno-objc-arc" src="src/ios/Base64ToGallery.m"/>
<config-file parent="/*" target="config.xml"> <config-file parent="/*" target="config.xml">
<feature name="Base64ToGallery"> <feature name="Base64ToGallery">
<param name="ios-package" value="Base64ToGallery"/> <param name="ios-package" value="Base64ToGallery"/>
@@ -25,12 +31,11 @@
</config-file> </config-file>
<header-file src="src/ios/Base64ToGallery.h"/> <header-file src="src/ios/Base64ToGallery.h"/>
<source-file compiler-flags="-fno-objc-arc" src="src/ios/Base64ToGallery.m"/>
</platform> </platform>
<!-- android --> <!-- android -->
<platform name="android"> <platform name="android">
<source-file src="src/android/Base64ToGallery.java" target-dir="src/it/nexxa/Base64ToGallery"/>
<config-file parent="/*" target="AndroidManifest.xml"> <config-file parent="/*" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
@@ -41,13 +46,12 @@
<param name="android-package" value="it.nexxa.base64ToGallery.Base64ToGallery"/> <param name="android-package" value="it.nexxa.base64ToGallery.Base64ToGallery"/>
</feature> </feature>
</config-file> </config-file>
<source-file src="src/android/Base64ToGallery.java" target-dir="src/it/nexxa/Base64ToGallery"/>
</platform> </platform>
<!-- wp8 --> <!-- wp8 -->
<platform name="wp8"> <platform name="wp8">
<source-file src="src/wp8/Base64ToGallery.cs"/>
<config-file parent="/*" target="config.xml"> <config-file parent="/*" target="config.xml">
<feature name="Base64ToGallery"> <feature name="Base64ToGallery">
<param name="wp-package" value="Base64ToGallery"/> <param name="wp-package" value="Base64ToGallery"/>
@@ -58,7 +62,5 @@
<config-file parent="/Deployment/App/Capabilities" target="Properties/WMAppManifest.xml"> <config-file parent="/Deployment/App/Capabilities" target="Properties/WMAppManifest.xml">
<Capability Name="ID_CAP_MEDIALIB_PHOTO"/> <Capability Name="ID_CAP_MEDIALIB_PHOTO"/>
</config-file> </config-file>
<source-file src="src/wp8/Base64ToGallery.cs"/>
</platform> </platform>
</plugin> </plugin>
+17 -7
View File
@@ -2,18 +2,28 @@
// Modules // Modules
var fs = require('fs'); var fs = require('fs');
var libxml = require('libxmljs'); var logger = require('nodemsg');
var pkg = require('../package.json'); var pkg = require('../package.json');
// CONSTS // CONSTS
var CONFIG_FILE = 'plugin.xml'; var CONFIG_FILE = 'plugin.xml';
var PLUGIN_ID = 'cordova-base64-to-gallery';
var ERROR_MSG = 'No "version" attribute found - Please check '+ CONFIG_FILE +' ("version" tag must follow "id" tag)';
var REGEXP = '(id="' + PLUGIN_ID + '" )(version="\\d+[.]\\d+[.]\\d+")';
var version = pkg.version; // Logic
var configContent = fs.readFileSync(CONFIG_FILE); var version = pkg.version;
var configXML = libxml.parseXmlString(configContent); var regex = new RegExp(REGEXP);
var configVersion = configXML.root().attr('version'); var config = fs.readFileSync(CONFIG_FILE, { encoding: 'utf8'});
// Exit if version tag not found
if (!regex.test(config)) {
logger.error(ERROR_MSG);
process.exit(1);
}
// Set version // Set version
configVersion.value(version); config = config.replace(regex, '$1version="' + version + '"');
fs.writeFileSync(CONFIG_FILE, configXML.toString()); fs.writeFileSync(CONFIG_FILE, config);
+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