2014-04-02 112 views
0

我已经创建了原生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 

非常感谢。

回答

4

最近有同样的,而在新的Xcode建设旧的cordova应用程序。

您应该检查Other linker flags在你的目标设定:

Other linker flags

对于debug构建配置,您可以使用-ObjC标志。 (What does the -ObjC linker flag do?,Why do I get a runtime exception of "selector not recognized" when linking against an Objective-C static library that contains categories?

如果在阅读上一个链接之后,您仍然想在release中使用此标志 - 就这样做。

否则,您应该将-force_load ${BUILT_PRODUCTS_DIR}/libCordova.a添加到发布链接程序标志。

要检查/编辑活动版本配置,请转至Product>Scheme>Edit schemeCmd <)。

+0

感谢您使用-force_load路径语法,我遇到了困难。 – Jason

相关问题