Javascript iOS本机应用程序,与Cordova 2.9.0集成
我已经创建了一个本机iOS应用程序(Xcode 5.1),我想通过btn、cordova(cordova 2.9.0)web视图(或者CDVViewController)打开。我成功地做到了这一点,web视图工作正常,它向我显示了网页,但当我嵌入cordova.js(在网页内)时,它会显示 CDVCommandQueue.mJavascript iOS本机应用程序,与Cordova 2.9.0集成,javascript,ios,cordova,uiwebview,jsonobject,Javascript,Ios,Cordova,Uiwebview,Jsonobject,我已经创建了一个本机iOS应用程序(Xcode 5.1),我想通过btn、cordova(cordova 2.9.0)web视图(或者CDVViewController)打开。我成功地做到了这一点,web视图工作正常,它向我显示了网页,但当我嵌入cordova.js(在网页内)时,它会显示 CDVCommandQueue.m - (void)fetchCommandsFromJs { // Grab all the queued commands from the JS side. NSStri
- (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('cordova/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;
}
}
无法将该值识别为json对象,并向我显示此错误消息
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString JSONObject]: unrecognized selector sent to instance
非常感谢。在新Xcode中构建旧的cordova应用程序时,最近也有同样的情况
您应该在目标设置中检查其他链接器标志
:
对于debug
构建配置,可以使用-ObjC
标志。(,)
如果在阅读了前面的链接后,您仍然希望在发布中使用此标志,请执行此操作
否则,您应该将-force_load${builded_PRODUCTS_DIR}/libCordova.a
添加到发布链接器标志中
要检查/编辑活动生成配置,请转到产品
编辑方案(Cmd最近也有相同的配置,当时正在新Xcode中生成旧的cordova应用程序
您应该在目标设置中检查其他链接器标志
:
对于调试
生成配置,可以使用-ObjC
标志。()
如果在阅读了前面的链接后,您仍然希望在发布中使用此标志,请执行此操作
否则,您应该将-force_load${builded_PRODUCTS_DIR}/libCordova.a
添加到发布链接器标志中
要检查/编辑活动生成配置,请转到Product
Scheme
编辑Scheme
(Cmd感谢您包含-force\u加载路径语法,我在这方面遇到了困难。感谢您包含-force\u加载路径语法,我在这方面遇到了困难。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString JSONObject]: unrecognized selector sent to instance