Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C errors after getting the IAP product response

This code is from the Phonegap Code: IAP Plugin. The error happens on the line of the code right after the "sent js". All the elements sent to the function are non-nil except for the last one 'nil'. I even logged them out to make sure they were sent. This code is right out of the plugin (https://github.com/usmart/InAppPurchaseManager-EXAMPLE) and has not been modified except for the logging. In the debugger i saw that none of the objects were nil, so i don't understand why the error is happening.

Here is the error:

[__NSArrayI JSONRepresentation]: unrecognized selector sent to instance 0xdc542d0 2013-02-13 23:26:17.209 GoblinSlots[4519:707] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI JSONRepresentation]: unrecognized selector sent to instance 0xdc542d0'

here is the code:

      - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:   (SKProductsResponse *)response
      {
        NSLog(@"got iap product response");
        for (SKProduct *product in response.products) {
            NSLog(@"sending js for %@", product.productIdentifier);
            NSLog(@"  title %@", product.localizedTitle );
            NSLog(@"  desc%@ - %@", product.localizedDescription, product.localizedPrice );


NSArray *callbackArgs = [NSArray arrayWithObjects:
                                 NILABLE(product.productIdentifier),
                                 NILABLE(product.localizedTitle),
                                 NILABLE(product.localizedDescription),
                                 NILABLE(product.localizedPrice),
                                 nil ];
        NSLog(@"sent js");

        NSString *js = [NSString stringWithFormat:@"%@.apply(plugins.inAppPurchaseManager, %@)", successCallback, [callbackArgs JSONSerialize]];
        NSLog(@"js: %@", js);
        [command writeJavascript: js];
    }
like image 393
Pascal Aschwanden Avatar asked Jan 30 '26 01:01

Pascal Aschwanden


2 Answers

All the stuff to do JSON serialization seems to be already included with the Cordova plugins. There's no need to download and install yet another JSON library.(a)

It appears that PhoneGap is in the process of switching from SBJson to JSONKit.(b)

PhoneGap is also in the process of changing all the JSON methods to use a "cdvjk_" prefix. (c)

As far as I can tell, something didn't quite go right during those changes. What I did was edit the file Plugins/InAppPurchaseManager.m , where I made these changes:

  • Add the line

#import <Cordova/CDVJSON.h>

  • Replace the line

return [self respondsToSelector:@selector(cdvjk_JSONString)] ? [self cdvjk_JSONString] : [self cdvjk_JSONRepresentation];

with

return [self JSONString];

. (What's the right way to push this or a better bugfix back to the nice PhoneGap people?)

like image 82
David Cary Avatar answered Jan 31 '26 20:01

David Cary


JSONRepresentation is a category that SBJson adds so you have to include SBJson.h in the class that uses it.

like image 30
Alexander Avatar answered Jan 31 '26 20:01

Alexander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!