I have created a native iOS app (Xcode 5.1), and I want to open via a btn, a cordova(Cordova 2.9.0) web view(Otherwise CDVViewController). I've succeed this and the web view works and it shows me the webpage, but when I embed the cordova.js (inside the webpage), the CDVCommandQueue.m
- (void)fetchCommandsFromJs
{
// Grab all the queued commands from the JS side.
NSString* queuedCommandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString:
@"cordova.require('cordova/exec').nativeFetchMessages()"];
NSLog(@"---- %@",queuedCommandsJSON);
[self enqueCommandBatch:queuedCommandsJSON];
if ([queuedCommandsJSON length] > 0) {
CDV_EXEC_LOG(@"Exec: Retrieved new exec messages by request.");
}
}
calls the above function and it executes the 'cordova.require('cordova/exec').nativeFetchMessages()', this function returns
[["Device748313476","Device","getDeviceInfo",[]],["NetworkStatus748313477","NetworkStatus","getConnectionInfo",[]]]
and then it passes this value to
- (void)executePending
{
// Make us re-entrant-safe.
if (_currentlyExecuting) {
return;
}
@try {
_currentlyExecuting = YES;
for (NSUInteger i = 0; i < [_queue count]; ++i) {
// Parse the returned JSON array.
NSLog(@"%@",[_queue objectAtIndex:i]);
**NSArray* commandBatch = [[_queue objectAtIndex:i] JSONObject];**
// Iterate over and execute all of the commands.
for (NSArray* jsonEntry in commandBatch) {
CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonEntry];
CDV_EXEC_LOG(@"Exec(%@): Calling %@.%@", command.callbackId, command.className, command.methodName);
if (![self execute:command]) {
#ifdef DEBUG
NSString* commandJson = [jsonEntry JSONString];
static NSUInteger maxLogLength = 1024;
NSString* commandString = ([commandJson length] > maxLogLength) ?
[NSString stringWithFormat:@"%@[...]", [commandJson substringToIndex:maxLogLength]] :
commandJson;
DLog(@"FAILED pluginJSON = %@", commandString);
#endif
}
}
}
[_queue removeAllObjects];
} @finally
{
_currentlyExecuting = NO;
}
}
My app is crashing because on this line
NSArray* commandBatch = [[_queue objectAtIndex:i] JSONObject];
doesn't recognize the value as json object and it gives me this error message
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString JSONObject]: unrecognized selector sent to instance
Thanks a lot.