iphone - 为什么 MKStoreKit isSubscriptionActive 方法总是返回 NO?

标签 iphone ios objective-c storekit mkstorekit

在通过 MKStoreKit 使用 StoreKit 的应用程序中工作时,我注意到检查订阅是否仍然有效的方法总是返回 0(NO 或 false)。

我跟踪了错误,发现在方法 - (BOOL) isSubscriptionActive:(NSString*) featureIdjsonObject由这一行生成:

id jsonObject = [NSJSONSerialization JSONObjectWithData:subscriptionProduct.receipt options:NSJSONReadingAllowFragments error:nil];

nil .

然后我检查了这个方法返回的错误,即:

[MKStoreManager isSubscriptionActive:]] Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (No value for key in object around character 15.) UserInfo=0x200c0300 {NSDebugDescription=No value for key in object around character 15.} (lldb)



于是我检查了收据,发现问题在于所谓的“JSON 收据”不是 JSON,因为它使用“=”而不是“:”。我想有人已经在处理这个问题,那么你的解决方案是什么?

编辑
我正在使用沙盒环境。

最佳答案

收据不是 JSON 对象。它是私有(private)格式,应该传递给 App Store 进行验证 - 您不应该尝试自己解析它。来自 In-App Purchase Programming Guide :

Note: On iOS, the contents and format of the store receipt is private and subject to change. Your application should not attempt to parse the receipt data directly. Use the mechanism described here to validate the receipt and retrieve the information stored inside it.



但是,从我对 MKSKSubscriptionProduct 实现的简要了解来看,这些代码似乎用来自 App Store 验证服务器的 JSON 响应覆盖了初始收据数据。因此,收据属性有时可能是有效的 JSON 对象,有时则不是。

此外,该代码似乎直接在 App Store 验证收据。这被认为是一种安全风险。引自 Apple's recommendations regarding the iOS5 App Store vulnerability :

The best practice for validating receipts is to send the receipt to your server, and have your server perform the validation with the App Store server. If your app connects to the App Store server directly from the device, your app may be affected by this vulnerability.



最重要的是,在我看来,MKStoreKit 实现中存在一些错误,可能值得向开发人员提出这些问题。

更新

我应该补充一点,App Store 沙盒环境往往会在最不合时宜的时候崩溃。可能只是沙箱未能响应收据验证请求,因此 MKSKSubscriptionProduct 收据保留其初始非 JSON 状态,因此失败。

如果是这种情况,您可能会发现它会在某个时间点突然开始工作,一旦沙盒被修复。

关于iphone - 为什么 MKStoreKit isSubscriptionActive 方法总是返回 NO?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16738551/

相关文章:

iphone - 使用 CGContextSetLineDash 绘制虚线

ios - 创建 Siri 快捷方式后在 Siri 中推荐快捷方式 - React Native

objective-c - 在 iOS 中录制 16bps 波形文件

ios - 创建一个NSString变量的C宏,变量名作为字符串的内容

objective-c - 事件范围

iphone - 在一段时间内显示标签

ios - 如何在 iOS 8 中使用 VideoToolbox.framework 播放 H264 视频文件?

php - 在 iOS 中下载视频和音频是否有特殊标记?

iOS 8 在不安装 Xcode 的情况下从用户设备读取控制台日志

objective-c - 在 Objective-C 中复制和 move 文件