diff --git a/CordovaLib/Classes/CDVPluginResult.h b/CordovaLib/Classes/CDVPluginResult.h index 71df67637..30dd9f92e 100644 --- a/CordovaLib/Classes/CDVPluginResult.h +++ b/CordovaLib/Classes/CDVPluginResult.h @@ -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; diff --git a/CordovaLib/Classes/CDVPluginResult.m b/CordovaLib/Classes/CDVPluginResult.m index 98c4e6f2f..03e696be4 100644 --- a/CordovaLib/Classes/CDVPluginResult.m +++ b/CordovaLib/Classes/CDVPluginResult.m @@ -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]; diff --git a/CordovaLib/Classes/CDVViewController.h b/CordovaLib/Classes/CDVViewController.h index 6f6c84207..d2a2feba6 100644 --- a/CordovaLib/Classes/CDVViewController.h +++ b/CordovaLib/Classes/CDVViewController.h @@ -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; diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m index 4c3658749..43f460960 100644 --- a/CordovaLib/Classes/CDVViewController.m +++ b/CordovaLib/Classes/CDVViewController.m @@ -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]; @@ -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:@" %@ ", loadErr]; - [self.webView loadHTMLString:html baseURL:nil]; - } + [self loadStartPageIntoWebView]; } - (NSArray*) parseInterfaceOrientations:(NSArray*)orientations @@ -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:@" %@ ", loadErr]; + [self.webView loadHTMLString:html baseURL:nil]; + } +} + - (void) didReceiveMemoryWarning { // iterate through all the plugin objects, and call hasPendingOperation diff --git a/CordovaLib/CordovaLibTests/CDVPluginResultJSONSerializationTests.m b/CordovaLib/CordovaLibTests/CDVPluginResultJSONSerializationTests.m index 236e92e7c..7a0eb6476 100644 --- a/CordovaLib/CordovaLibTests/CDVPluginResultJSONSerializationTests.m +++ b/CordovaLib/CordovaLibTests/CDVPluginResultJSONSerializationTests.m @@ -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],