From b07bc28fae69af95f4f5d2cba5edb8c4ab6185e5 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Wed, 30 Mar 2016 15:19:14 -0400 Subject: [PATCH] Start on ImageEditor for iOS --- .gitignore | 1 + README.md | 12 ++++++++++++ plugin.xml | 17 +++++++++++++++++ src/ios/CDVImageEditor.h | 12 ++++++++++++ src/ios/CDVImageEditor.m | 37 ++++++++++++++++++++++--------------- 5 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 src/ios/CDVImageEditor.h diff --git a/.gitignore b/.gitignore index c269146..7a5f57f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .idea .DS_Store /node_modules/ +src/ios/AdobeCreativeSDKFrameworks/* diff --git a/README.md b/README.md index bf8cb12..a4e46bf 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,18 @@ phonegap-plugin-csdk-image-editor ------------------------ +# Prerequisites + +Before you can work with the Creative SDK, you must register your application and get Client ID and Client Secret values. For details, see [Registering Your Application](https://creativesdk.adobe.com/docs/ios/#/articles/gettingstarted/index.html). + +To get the iOS SDK, go to the [Downloads page](https://creativesdk.adobe.com/downloads.html), download the ZIP files, and extract them to the src/ios folder of this plugin. It should create a AdobeCreativeSDKFrameworks folder. The ZIP files contain all the frameworks in the Creative SDK but for this plugin we will only be using the AdobeCreativeSDKCore.framework. + +The following software is required: +- Xcode 7 or higher +- iOS 8.2 or higher + +# Installation + To add to your app: ``` diff --git a/plugin.xml b/plugin.xml index d27a074..6ea76e1 100644 --- a/plugin.xml +++ b/plugin.xml @@ -48,7 +48,24 @@ + + + + + + + + + + + + + + + + + diff --git a/src/ios/CDVImageEditor.h b/src/ios/CDVImageEditor.h new file mode 100644 index 0000000..812a491 --- /dev/null +++ b/src/ios/CDVImageEditor.h @@ -0,0 +1,12 @@ +#import + +@interface CDVImageEditor : CDVPlugin +{ + NSString *callbackId; +} + +@property (nonatomic, retain) NSString *callbackId; + +- (void)edit:(CDVInvokedUrlCommand*)command; + +@end diff --git a/src/ios/CDVImageEditor.m b/src/ios/CDVImageEditor.m index 0e4419b..49a4c99 100644 --- a/src/ios/CDVImageEditor.m +++ b/src/ios/CDVImageEditor.m @@ -17,32 +17,39 @@ Licensed to the Apache Software Foundation (ASF) under one under the License. */ -#import +#import +#import "CDVImageEditor.h" -@interface CDVEcho : CDVPlugin -@end +@implementation CDVImageEditor -@implementation CDVEcho +@synthesize callbackId; -- (void)echo:(CDVInvokedUrlCommand*)command +- (void)edit:(CDVInvokedUrlCommand*)command { - id message = [command.arguments objectAtIndex:0]; - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message]; + self.callbackId = command.callbackId; + + NSString *imageUri = [command.arguments objectAtIndex:0]; + NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUri]]; + UIImage *image = [UIImage imageWithData:imageData]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + AdobeUXImageEditorViewController *editorController = + [[AdobeUXImageEditorViewController alloc] initWithImage:image]; + [editorController setDelegate:self]; + [self.viewController presentViewController:editorController animated:YES completion:nil]; } -- (void)echoAsyncHelper:(NSArray*)args +- (void)photoEditor:(AdobeUXImageEditorViewController *)editor finishedWithImage:(UIImage *)image { - [self.commandDelegate sendPluginResult:[args objectAtIndex:0] callbackId:[args objectAtIndex:1]]; + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; + [self.viewController dismissViewControllerAnimated:YES completion:nil]; } -- (void)echoAsync:(CDVInvokedUrlCommand*)command +- (void)photoEditorCanceled:(AdobeUXImageEditorViewController *)editor { - id message = [command.arguments objectAtIndex:0]; - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message]; - - [self performSelector:@selector(echoAsyncHelper:) withObject:[NSArray arrayWithObjects:pluginResult, command.callbackId, nil] afterDelay:0]; + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; + [self.viewController dismissViewControllerAnimated:YES completion:nil]; } @end