- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个付费的 iOS 应用程序。
我需要从 Apple AppStore 收据中获取 original_application_version
编号(用户购买的第一个版本)。
为了获取收据,当我的应用加载时,我使用了 checkReceiptFromAppStore()
函数:
func checkReceiptFromAppStore() {
let receipt = self.getReceipt()
print("receipt Data is: \(receipt)") // prints this: receipt Data is: Optional(5141 bytes)
}
getReceipt()
函数如下:
func getReceipt() -> Data? {
if Bundle.main.appStoreReceiptURL != nil {
print("app receipt: \(Bundle.main.appStoreReceiptURL)")
do {
let receiptData = try Data(contentsOf: Bundle.main.appStoreReceiptURL!)
return receiptData
} catch {
print("error converting receipt to Data: \(error.localizedDescription)")
}
}
return nil
}
I've watched WWDC 2017 Advanced StoreKit video about In App purchases and receipt validation and WWDC 2013 Video about using Receipts, read different resources related to my problem (this, this, this, this, this, this, and this...), but I still don't understand what to do next to get the "original_application_version" from the App Store Receipt. I need only this field and don't understand why is it so hard to get it. I've read this too: https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html
我认为只要在我运行 print("receipt Data is: (receipt)") 时收据不是 nil,它会打印出:收据数据是:可选(5141 字节)
我可以假设我应该解析收据以获取该字段。我可以使用 Decodable 吗?有没有最简单的方法来获取此 original_application_version
字段?是否可以在没有收据验证的情况下执行此操作?
我需要获取 original_application_version
字段来检测用户购买的第一个版本的数量。如果您知道获得第一个购买的版本号的任何其他解决方案,我很乐意听到它们。
我正在使用 Xcode 9、Swift 4、iOS 11 进行开发
感谢任何答案,谢谢。
最佳答案
申请收据中的所有收据字段均为二进制格式。您应该使用任何类型的应用程序收据解码器才能获得 original_application_version。在使用其内容之前验证应用收据总是一件好事。例如,您可以使用 RMStore 框架 ( RMStore )。它包含收据验证器和解码器。示例 Obj-C 来源:
RMAppReceipt *appReceipt = RMAppReceipt.bundleReceipt;
if (appReceipt != nil &&
[appReceipt.originalAppVersion length] > 0 &&
![appReceipt.originalAppVersion isEqualToString:@"1.0"]) {
//Process your original app version
} else {
//Probably it is sandbox mode or app install via Xcode
//Or maybe you should force app receipt refresh
}
关于ios - iOS 11 如何从 iOS Receipt 中获取 original_application_version(第一个购买的版本号)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47924123/
我是一名优秀的程序员,十分优秀!