此代码来自 Phonegap 代码:IAP 插件。错误发生在“发送的js”之后的代码行上。除了最后一个“nil”之外,发送到该函数的所有元素均非零。我什至将它们注销以确保它们已发送。该代码直接来自插件(https://github.com/usmart/InAppPurchaseManager-示例 https://github.com/usmart/InAppPurchaseManager-EXAMPLE)并且除了日志记录之外没有被修改。在调试器中我看到没有一个对象为零,所以我不明白为什么会发生错误。
这是错误:
[__NSArrayI JSONRepresentation]:发送到的无法识别的选择器
实例0xdc542d0
2013-02-13 23:26:17.209 妖精老虎机[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];
}
所有用于 JSON 序列化的东西似乎已经包含在 Cordova 插件中。
无需下载并安装另一个 JSON 库。(a) http://codemonger.tumblr.com/post/11098641444/encoding-json-in-objective-c-with-phonegap
看来 PhoneGap 正在从 SBJson 切换到 JSONKit。(b) https://github.com/phonegap/phonegap-plugins/pull/217
PhoneGap 还正在更改所有 JSON 方法以使用“cdvjk_”前缀。(c) https://github.com/phonegap/phonegap-plugins/pull/876
据我所知,在这些变化期间有些事情不太顺利。
我所做的是编辑文件 Plugins/InAppPurchaseManager.m ,我在其中进行了以下更改:
#import <Cordova/CDVJSON.h>
return [self respondsToSelector:@selector(cdvjk_JSONString)] ? [self cdvjk_JSONString] : [self cdvjk_JSONRepresentation];
with
return [self JSONString];
。 (将这个或更好的错误修复推回给优秀的 PhoneGap 人员的正确方法是什么?)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)