多年来我在应用程序商店中已有一个应用程序。用户必须付费才能下载该应用程序。现在我想通过实施应用内购买转向“免费增值”模式。 我希望对我的应用程序的先前购买者公平。 我搜索并阅读了很多关于这个主题的内容,它仍然让我感到害怕,主要是因为它总是归结为
解析原始交易收据和“解析”加密的东西,例如“原始应用程序版本字段” ...我非常希望,新的 StoreKit 2 为这个非常常见的问题提供更多选项,但找不到它。 所以我在这里问:在
StoreKit 2中是否有一种更简单的方法可以从原始购买中检索更多“可读”数据? 任何提示将不胜感激。👍🏻
do {
// Get the appTransaction.
let shared = try await AppTransaction.shared
if case .verified(let appTransaction) = shared {
// Hard-code the major version number in which the app's business model changed.
let newBusinessModelMajorVersion = "2"
// Get the major version number of the version the customer originally purchased.
let versionComponents = appTransaction.originalAppVersion.split(separator: ".")
let originalMajorVersion = versionComponents[0]
if originalMajorVersion < newBusinessModelMajorVersion {
// This customer purchased the app before the business model changed.
// Deliver content that they're entitled to based on their app purchase.
}
else {
// This customer purchased the app after the business model changed.
}
}
}
catch {
// Handle errors.
}
// Iterate through any other products the customer purchased.
for await result in Transaction.currentEntitlements {
if case .verified(let transaction) = result {
// Deliver the content based on the customer's current entitlements.
}
}