Skip to content

Commit

Permalink
Merge pull request #1 from forcedotcom/bool_plugin_result
Browse files Browse the repository at this point in the history
Re-adding 1.2 updates
  • Loading branch information
khawkins committed Jul 2, 2012
2 parents b48fc30 + 9dbf619 commit 091f06b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
1 change: 1 addition & 0 deletions CordovaLib/Classes/CDVPluginResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ typedef enum {
+(CDVPluginResult*) resultWithStatus: (CDVCommandStatus) statusOrdinal messageAsArray: (NSArray*) theMessage;
+(CDVPluginResult*) resultWithStatus: (CDVCommandStatus) statusOrdinal messageAsInt: (int) theMessage;
+(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 messageToErrorObject: (int) errorCode;

Expand Down
5 changes: 5 additions & 0 deletions CordovaLib/Classes/CDVPluginResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ +(CDVPluginResult*) resultWithStatus: (CDVCommandStatus) statusOrdinal messageAs
return [[[self alloc] initWithStatus: statusOrdinal message: [NSNumber numberWithDouble: theMessage]] autorelease];
}

+(CDVPluginResult*) resultWithStatus: (CDVCommandStatus) statusOrdinal messageAsBool: (BOOL) theMessage
{
return [[[self alloc] initWithStatus: statusOrdinal message: [NSNumber numberWithBool: theMessage]] autorelease];
}

+(CDVPluginResult*) resultWithStatus: (CDVCommandStatus) statusOrdinal messageAsDictionary: (NSDictionary*) theMessage
{
return [[[self alloc] initWithStatus: statusOrdinal message: theMessage] autorelease];
Expand Down
6 changes: 6 additions & 0 deletions CordovaLib/Classes/CDVViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@

- (void) printMultitaskingInfo;
- (void) createGapView;

/**
* Sets up the local start page and loads it into the web view.
*/
- (void)loadStartPageIntoWebView;

- (CDVCordovaView*) newCordovaViewWithFrame:(CGRect)bounds;

- (int) executeQueuedCommands;
Expand Down
45 changes: 25 additions & 20 deletions CordovaLib/Classes/CDVViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,6 @@ - (void) viewDidLoad

///////////////////

NSString* startFilePath = [self pathForResource:self.startPage];
NSURL* appURL = nil;
NSString* loadErr = nil;

if (startFilePath == nil) {
loadErr = [NSString stringWithFormat:@"ERROR: Start Page at '%@/%@' was not found.", self.wwwFolderName, self.startPage];
NSLog(@"%@", loadErr);
self.loadFromString = YES;
appURL = nil;
} else {
appURL = [NSURL fileURLWithPath:startFilePath];
}

//// Fix the iOS 5.1 SECURITY_ERR bug (CB-347), this must be before the webView is instantiated ////

[CDVLocalStorage __verifyAndFixDatabaseLocations];
Expand Down Expand Up @@ -230,13 +217,7 @@ - (void) viewDidLoad

///////////////////

if (!loadErr) {
NSURLRequest *appReq = [NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
[self.webView loadRequest:appReq];
} else {
NSString* html = [NSString stringWithFormat:@"<html><body> %@ </body></html>", loadErr];
[self.webView loadHTMLString:html baseURL:nil];
}
[self loadStartPageIntoWebView];
}

- (NSArray*) parseInterfaceOrientations:(NSArray*)orientations
Expand Down Expand Up @@ -377,6 +358,30 @@ - (void) createGapView
}
}

- (void)loadStartPageIntoWebView
{
NSString* startFilePath = [self pathForResource:self.startPage];
NSURL* appURL = nil;
NSString* loadErr = nil;

if (startFilePath == nil) {
loadErr = [NSString stringWithFormat:@"ERROR: Start Page at '%@/%@' was not found.", self.wwwFolderName, self.startPage];
NSLog(@"%@", loadErr);
self.loadFromString = YES;
appURL = nil;
} else {
appURL = [NSURL fileURLWithPath:startFilePath];
}

if (!loadErr) {
NSURLRequest *appReq = [NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
[self.webView loadRequest:appReq];
} else {
NSString* html = [NSString stringWithFormat:@"<html><body> %@ </body></html>", loadErr];
[self.webView loadHTMLString:html baseURL:nil];
}
}

- (void) didReceiveMemoryWarning {

// iterate through all the plugin objects, and call hasPendingOperation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ - (void)testSerializingMessageAsDouble {
STAssertTrue([[NSNumber numberWithDouble:5.5] isEqual:message], nil);
}

- (void)testSerializingMessageAsBool {
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:YES];
NSDictionary *dic = [[result toJSONString] objectFromJSONString];
NSNumber *message = [dic objectForKey:@"message"];
STAssertTrue([[NSNumber numberWithBool:YES] isEqual:message], nil);
}

- (void)testSerializingMessageAsArray {
NSArray *testValues = [NSArray arrayWithObjects:
[NSNull null],
Expand Down

0 comments on commit 091f06b

Please sign in to comment.