iOS 应用的收据验证码,无法使用
Receipt-Validation code for iOS app, not working
我第一次在 iOS 应用程序中实现了 Receipt-Validation
代码,紧随 Raywenderlich tutorial
尽管在测试过程中它运行良好,但使用了 Sandbox。实际上,它并没有像预期的那样工作。
下载应用后,所有功能从一开始就可用;意味着没有检查 iap 内容的购买。
在 Sandbox 的情况下,我需要进行购买才能获得收据,"making a purchase" 意味着 "getting the content of the 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 .....
}
}
您应该检查类型为 17xx 的字段,您可以在其中找到产品标识符(字段类型 1702)和购买日期(字段类型 1704)。这在您在阅读应用内购买部分提到的 Raywenderlich 教程中有所描述。
因此,您可以检查用户是否使用您感兴趣的产品标识符购买了 IAP。产品标识符与您在 App Store Connect 中选择的相同,位于我的应用程序 -> 功能 -> IAP。
我第一次在 iOS 应用程序中实现了 Receipt-Validation
代码,紧随 Raywenderlich tutorial
尽管在测试过程中它运行良好,但使用了 Sandbox。实际上,它并没有像预期的那样工作。
下载应用后,所有功能从一开始就可用;意味着没有检查 iap 内容的购买。
在 Sandbox 的情况下,我需要进行购买才能获得收据,"making a purchase" 意味着 "getting the content of the 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 .....
}
}
您应该检查类型为 17xx 的字段,您可以在其中找到产品标识符(字段类型 1702)和购买日期(字段类型 1704)。这在您在阅读应用内购买部分提到的 Raywenderlich 教程中有所描述。
因此,您可以检查用户是否使用您感兴趣的产品标识符购买了 IAP。产品标识符与您在 App Store Connect 中选择的相同,位于我的应用程序 -> 功能 -> IAP。