继Raywenderlich tutorial之后,我第一次在iOS应用程序中实现了Receipt-Validation代码
尽管它在测试期间运行良好,但使用的是沙盒。在现实中,它并不像预期的那样工作。
下载应用程序后,所有功能都可以从start开始使用;这意味着无需检查iap内容的购买情况。
在Sandbox的例子中,我需要购买才能获得收据,而“购买”意味着“获取iap的内容”。
据我所知,在现实世界中,收据是随应用程序一起提供的。我的解释是,我可能没有检查我应该在代码中做什么。
该领域专家的任何指导都将非常感谢。
看一下代码,似乎(确实)没有太多的检查,除了确保他们的是一个有效的(格式良好的)收据。但我想我需要更多的东西来检查IAP的内容是否已经支付。
下面是我认为的相关代码:
func validateReceipt() {
receipt = Receipt()
if let receiptStatus = receipt?.receiptStatus {
guard receiptStatus == .validationSuccess else {
return
}
// If verification succeed, we show information contained in the receipt.
// print("Bundle Identifier: \(receipt!.bundleIdString!)")
// print("Bundle Version: \(receipt!.bundleVersionString!)")
if let originalVersion = receipt?.originalAppVersion {
//print("originalVersion: \(originalVersion)")
} else {
//print("originalVersion: Not Provided")
}
if let receiptExpirationDate = receipt?.expirationDate {
//print("Expiration Date: \(formatDateForUI(receiptExpirationDate))")
} else {
//print("Expiration Date: Not Provided")
}
if let receiptCreation = receipt?.receiptCreationDate {
//print("receiptCreation: \(formatDateForUI(receiptCreation))")
} else {
//print("receiptCreation: Not Provided")
}
// At this point we should enable full features if it is not yet the case.
.... code to unlock full features .....
}
}发布于 2019-04-14 14:27:16
您应该检查类型为17xx的字段,您可以在其中找到产品标识符(字段类型1702)和购买日期(字段类型1704)。你在部分阅读应用内购买中提到的Raywenderlich教程中描述了这一点。
因此,您可以查看用户是否购买了带有您感兴趣的产品标识的IAP。产品标识符与您在App Store Connect at MyApps -> Feature -> IAP上选择的相同。
https://stackoverflow.com/questions/55672264
复制相似问题