You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2013/01/14 22:50:22 UTC
ios commit: [ios] CB-2215 - Implement ArrayBuffer native->js.
Updated Branches:
refs/heads/master cc4688d1d -> 6fe1f3d8e
[ios] CB-2215 - Implement ArrayBuffer native->js.
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/6fe1f3d8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/6fe1f3d8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/6fe1f3d8
Branch: refs/heads/master
Commit: 6fe1f3d8e011bf79fec9c5c2857b63d7a2621436
Parents: cc4688d
Author: Michal Mocny <mm...@gmail.com>
Authored: Fri Jan 11 14:46:01 2013 -0500
Committer: Michal Mocny <mm...@gmail.com>
Committed: Mon Jan 14 16:42:01 2013 -0500
----------------------------------------------------------------------
CordovaLib/Classes/CDVEcho.m | 18 ++++++++++++++++--
CordovaLib/Classes/CDVPluginResult.h | 1 +
CordovaLib/Classes/CDVPluginResult.m | 11 +++++++++++
3 files changed, 28 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/6fe1f3d8/CordovaLib/Classes/CDVEcho.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVEcho.m b/CordovaLib/Classes/CDVEcho.m
index 9cda957..75e6c10 100644
--- a/CordovaLib/Classes/CDVEcho.m
+++ b/CordovaLib/Classes/CDVEcho.m
@@ -22,9 +22,23 @@
@implementation CDVEcho
+- (CDVPluginResult*)createEchoPluginResult:(CDVInvokedUrlCommand*)command
+{
+ id message = [command.arguments objectAtIndex:0];
+ CDVPluginResult* pluginResult = nil;
+
+ if ([message isKindOfClass:[NSData class]]) {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArrayBuffer:message];
+ } else {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:message];
+ }
+
+ return pluginResult;
+}
+
- (void)echo:(CDVInvokedUrlCommand*)command
{
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[command.arguments objectAtIndex:0]];
+ CDVPluginResult* pluginResult = [self createEchoPluginResult:command];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@@ -36,7 +50,7 @@
- (void)echoAsync:(CDVInvokedUrlCommand*)command
{
- CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[command.arguments objectAtIndex:0]];
+ CDVPluginResult* pluginResult = [self createEchoPluginResult:command];
[self performSelector:@selector(echoAsyncHelper:) withObject:[NSArray arrayWithObjects:pluginResult, command.callbackId, nil] afterDelay:0];
}
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/6fe1f3d8/CordovaLib/Classes/CDVPluginResult.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVPluginResult.h b/CordovaLib/Classes/CDVPluginResult.h
index 061e30d..8683205 100644
--- a/CordovaLib/Classes/CDVPluginResult.h
+++ b/CordovaLib/Classes/CDVPluginResult.h
@@ -46,6 +46,7 @@ typedef enum {
+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDouble:(double)theMessage;
+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsBool:(BOOL)theMessage;
+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDictionary:(NSDictionary*)theMessage;
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArrayBuffer:(NSData*)theMessage;
+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageToErrorObject:(int)errorCode;
+ (void)setVerbose:(BOOL)verbose;
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/6fe1f3d8/CordovaLib/Classes/CDVPluginResult.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVPluginResult.m b/CordovaLib/Classes/CDVPluginResult.m
index 3103ad1..d9ba08f 100644
--- a/CordovaLib/Classes/CDVPluginResult.m
+++ b/CordovaLib/Classes/CDVPluginResult.m
@@ -20,6 +20,7 @@
#import "CDVPluginResult.h"
#import "CDVJSON.h"
#import "CDVDebug.h"
+#import "NSData+Base64.h"
@interface CDVPluginResult ()
@@ -98,6 +99,16 @@ static NSArray* org_apache_cordova_CommandStatusMsgs;
return [[self alloc] initWithStatus:statusOrdinal message:theMessage];
}
++ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArrayBuffer:(NSData*)theMessage
+{
+ NSDictionary* arrDict = [NSDictionary dictionaryWithObjectsAndKeys:
+ @"ArrayBuffer", @"CDVType",
+ [theMessage base64EncodedString], @"data",
+ nil];
+
+ return [[self alloc] initWithStatus:statusOrdinal message:arrDict];
+}
+
+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageToErrorObject:(int)errorCode
{
NSDictionary* errDict = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:errorCode] forKey:@"code"];