I am implementing in-app purchases and am currently reading up on how to best store the information if you don't have your own server. I came across these two articles by the same author, two years apart:
- Check if user has purchased in-app item / product using Keychain (2018)
- Read and validate in-app purchase receipt locally using TPInAppReceipt (2020)
Before, I thought receipt validation was exclusively done to check if the purchase was authentic/not faked. But seeing this part in the second article:
// (He's using a third-party library TPInAppReceipt)
if let receipt = try? InAppReceipt.localReceipt(){
if receipt.containsPurchase(ofProductIdentifier: "your.product.identifier"){
// user has purchased this product
// return true
}
}
made me think this is the same as storing the purchase on Keychain, isn't it?
Am I correct in my assumptions, that:
- Keychain (or anything else that's safe) = only storage of purchase info
- Receipt = validation of purchase AND storage of purchase info
So is the receipt storage info a new functionality, or why else would someone store purchases somewhere else when you can use the receipt anyway?
Edit: I found this article that seems to confirm my assumptions to some degree:
Implementing In-App Purchases without Keychain and UserDefaults)
The author makes the point that this technique is probably not more widely used because
- It only works for non-consumable products and auto-renewable subscriptions
- It's hard to implement