You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/03/16 19:14:49 UTC

[17/29] ios commit: using require in pluginresult helper funcs. added getConnectionInfo method to connection plugin to line up with other platforms

using require in pluginresult helper funcs. added getConnectionInfo method to connection plugin to line up with other platforms


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/e0023ca5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/e0023ca5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/e0023ca5

Branch: refs/heads/master
Commit: e0023ca51090ada14cc5a8dc770ca44be085cff9
Parents: 22fc69c
Author: Fil Maj <fi...@nitobi.com>
Authored: Thu Feb 23 11:52:03 2012 -0800
Committer: Fil Maj <ma...@gmail.com>
Committed: Fri Mar 16 10:56:49 2012 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVConnection.m   |   10 ++++++++--
 CordovaLib/Classes/CDVPluginResult.m |   10 ++++++----
 2 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e0023ca5/CordovaLib/Classes/CDVConnection.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVConnection.m b/CordovaLib/Classes/CDVConnection.m
index ba19f70..f3bd758 100644
--- a/CordovaLib/Classes/CDVConnection.m
+++ b/CordovaLib/Classes/CDVConnection.m
@@ -29,9 +29,15 @@
 
 @synthesize connectionType, internetReach;
 
-- (NSString*) getConnectionInfo
+- (void) getConnectionInfo:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
 {
-    return self.connectionType;
+    CDVPluginResult* result = nil;
+    NSString* jsString = nil;
+	NSString* callbackId = [arguments objectAtIndex:0];
+    
+    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:self.connectionType];
+    jsString = [result toSuccessCallbackString:callbackId];
+    [self writeJavascript:jsString];
 }
 
 - (NSString*) w3cConnectionTypeFor:(CDVReachability*)reachability

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/e0023ca5/CordovaLib/Classes/CDVPluginResult.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVPluginResult.m b/CordovaLib/Classes/CDVPluginResult.m
index 57f1577..3f42516 100644
--- a/CordovaLib/Classes/CDVPluginResult.m
+++ b/CordovaLib/Classes/CDVPluginResult.m
@@ -137,28 +137,30 @@ static NSArray* org_apache_cordova_CommandStatusMsgs;
 	DLog(@"PluginResult:toJSONString - %@", resultString);
 	return resultString;
 }
+// TODO: get rid of casting
 -(NSString*) toSuccessCallbackString: (NSString*) callbackId
 {
 	NSString* successCB;
 	
 	if ([self cast] != nil) {
-		successCB = [NSString stringWithFormat: @"var temp = %@(%@);\nCordova.callbackSuccess('%@',temp);", self.cast, [self toJSONString], callbackId];
+		successCB = [NSString stringWithFormat: @"var temp = %@(%@);\nrequire('cordova').callbackSuccess('%@',temp);", self.cast, [self toJSONString], callbackId];
 	}
 	else {
-		successCB = [NSString stringWithFormat:@"Cordova.callbackSuccess('%@',%@);", callbackId, [self toJSONString]];			
+		successCB = [NSString stringWithFormat:@"require('cordova').callbackSuccess('%@',%@);", callbackId, [self toJSONString]];			
 	}
 	DLog(@"PluginResult toSuccessCallbackString: %@", successCB);
 	return successCB;
 }
+// TODO: get rid of casting
 -(NSString*) toErrorCallbackString: (NSString*) callbackId
 {
 	NSString* errorCB = nil;
 	
 	if ([self cast] != nil) {
-		errorCB = [NSString stringWithFormat: @"var temp = %@(%@);\nCordova.callbackError('%@',temp);", self.cast, [self toJSONString], callbackId];
+		errorCB = [NSString stringWithFormat: @"var temp = %@(%@);\nrequire('cordova').callbackError('%@',temp);", self.cast, [self toJSONString], callbackId];
 	}
 	else {
-		errorCB = [NSString stringWithFormat:@"Cordova.callbackError('%@',%@);", callbackId, [self toJSONString]];
+		errorCB = [NSString stringWithFormat:@"require('cordova').callbackError('%@',%@);", callbackId, [self toJSONString]];
 	}
 	DLog(@"PluginResult toErrorCallbackString: %@", errorCB);
 	return errorCB;