0

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.

iParianos
  • 51
  • 5

1 Answers1

4

Had the same recently, while was building old cordova app in new Xcode.

You should check Other linker flags in Your target settings:

Other linker flags

For the debug build configuration You could use -ObjC flag. (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?)

If after reading previous links, You still want to use this flag in release — just do it.

Otherwise, You should add -force_load ${BUILT_PRODUCTS_DIR}/libCordova.a to the release linker flag.

In order to check/edit active build configuration go to Product > Scheme > Edit scheme (Cmd <).

Community
  • 1
  • 1
Rustem Mustafin
  • 957
  • 1
  • 11
  • 23
  • Thank you for including the -force_load path syntax, I was having difficulty with that. – Jason May 09 '14 at 20:33