此代码来自 Phonegap 代码:IAP 插件。错误发生在“sent js”之后的代码行上。除了最后一个“nil”之外,发送到函数的所有元素都是非零的。我什至将它们注销以确保它们已发送。此代码就在插件之外(https://github.com/usmart/InAppPurchaseManager-EXAMPLE),除了日志记录之外没有被修改。在调试器中,我看到没有一个对象为零,所以我不明白为什么会发生错误。
这是错误:
[__NSArrayI JSONRepresentation]:无法识别的选择器发送到实例 0xdc542d0 2013-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];
}