获得IAP产品响应后出现Objective-C错误



此代码来自Phonegap代码:IAP插件。错误发生在"send-js"之后的代码行。除了最后一个"nil"元素外,发送到函数的所有元素都是非nil元素。我甚至把它们注销,以确保它们被发送出去。此代码直接来自插件(https://github.com/usmart/InAppPurchaseManager-EXAMPLE)并且除了日志之外没有被修改。在调试器中,我看到没有一个对象是nil,所以我不明白为什么会发生错误。

错误如下:

[__NSArrayI JSONRepresentation]:无法识别的选择器发送到实例0xdc542d02013-02-13 23:26:17.209 GoblinSlots[4519:707]*由于未捕获异常"NSInvalidArgumentException"而终止应用程序,原因:'-[__NSArrayI JSONRepresentation]:无法识别的选择器已发送到实例0xdc542d0'

这是代码:

      - (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];
    }

Cordova插件似乎已经包含了所有进行JSON序列化的内容。不需要下载并安装另一个JSON库。(a)

PhoneGap似乎正在从SBJson切换到JSONKit。(b)

PhoneGap还在更改所有JSON方法以使用"cdvjk_"前缀。(c)

据我所知,在这些变化中,有些事情并不太顺利。我所做的是编辑文件Plugins/InAppPurchaseManager.m,在那里我做了以下更改:

  • 添加行

#import <Cordova/CDVJSON.h>

  • 更换线路

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

带有

return [self JSONString];

(将此错误或更好的错误修复程序推回到好的PhoneGap用户的正确方法是什么?)

JSONRepresentationSBJson添加的一个类别,因此必须将SBJson.h包含在使用它的类别中。

最新更新