Reputation: 57
this is my cide to get the receipt for the in app purchsae as part of my app. It returns to me saying in the logs, "Optional(5107 Bytes)". So there is abviosly a receipt file there but I just wanted to find a few wats to parse/decode this receipt to gain access to the info in those bytes.
The Code(first function in viewDidLoad() so to check the receipt)
func checkReceiptFromAppStore() {
let receipt = self.getReceipt()
print("receipt Data is: \(receipt)") // prints this: receipt Data is: Optional(5107 bytes)
}
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
}
Any Help will be greatly appreciated. Thanks
Upvotes: 1
Views: 2049
Reputation: 3177
The receipt is an encoded binary file. The Data
you get can’t be read and parsed as easily.
Docs: Locate and Parse the Receipt
Search for receipt validation on GitHub for examples of implementation.
Upvotes: 2