Objective-C errors after receiving a response for an IAP product

This code is from Phonegap code: IAP plugin. The error happens in the line of code right after the "submitted js". All elements passed to the function are non-zero except for the last "nil". I even wrote them out to make sure they were sent. This code is right from the plugin ( https://github.com/usmart/InAppPurchaseManager-EXAMPLE ) and hasn't been changed other than the log. In the debugger, I saw that none of the objects had a nickname, so I don't understand why the error occurs.

Here is the error:

[__ NSArrayI JSONRepresentation]: unrecognized selector sent to instance 0xdc542d0 2013-02-13 23: 26: 17.209 GoblinSlots [4519: 707] * Application terminated due to uncaught "NSInvalidArgumentException", reason: '- [__ NSArsentI 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];
    }

      

+3


source to share


2 answers


JSONRepresentation

is the category that adds SBJson

, so you must include SBJson.h

in the class that uses it.



+1


source


Everything you need to do to serialize JSON seems to be included in the Cordova plugins already. There is no need to download and install another JSON library. (a)

It looks like PhoneGap is in the process of moving from SBJson to JSONKit. (b)

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

As far as I can tell, nothing worked during these changes. I made an edit to the Plugins / InAppPurchaseManager.m file where I made these changes:

  • Add the line

#import <Cordova/CDVJSON.h>



  • Replace string

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

from

return [self JSONString];

... (What's the right way to push this or improve the fix for good PhoneGap users?)

+3


source







All Articles