我已经创建了原生iOS应用程序(Xcode 5.1),并且我想通过btn,cordova(科尔多瓦2.9.0)web视图(否则为CDVViewController)打开。我已经成功这个在网络上查看作品,它显示我的网页,但是当我嵌入cordova.js(网页内),该 CDVCommandQueue.miOS原生应用程序,与科尔多瓦集成2.9.0
- (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.");
}
}
调用上面的函数,它执行该 'cordova.require(' 科尔多瓦/ EXEC ')。nativeFetchMessages()', 此函数返回
[["Device748313476","Device","getDeviceInfo",[]],["NetworkStatus748313477","NetworkStatus","getConnectionInfo",[]]]
然后将此值传递给
- (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;
}
}
我的应用程序崩溃,因为在这一行
NSArray* commandBatch = [[_queue objectAtIndex:i] JSONObject];
无法识别值作为JSON对象,这让我这个错误消息
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString JSONObject]: unrecognized selector sent to instance
非常感谢。
感谢您使用-force_load路径语法,我遇到了困难。 – Jason