This is re-posted from this Stack Overflow post.
I am looking at validating the purchase of a paid app from Mac AppStore. Based on this WWDC video about StoreKit 2, I am attempting to this with AppTransaction.
I have not found meaningful high-level documentation about this specific use case beyond that.
My approach is to first get the "cached" AppTransaction
by calling AppTransaction.shared.
If that is not there I proceed to getting it from Apple, via AppTransaction.refresh().
If they don't have it, or when the network is down, the user automagically gets the familiar "log in to your store account" UI that has been around as long as the Mac AppStore.
Once I have the AppTransaction
I use it to verify we are on the right device, using code like this, where the returned Bool
represents validation success:
guard let deviceVID = AppStore.deviceVerificationID?.uuidString.lowercased() else { return false }
let nonce = appTransaction.deviceVerificationNonce.uuidString.lowercased()
let combo = nonce + deviceVID
let digest = SHA384.hash(data: Data(combo.utf8))
return (digest == appTransaction.deviceVerification)
My first question is: Does that look like the right approach? Is there something else I should do, or check?
My second question is around testing this approach. Refreshing the AppTransaction
in the sandbox invariably yields a valid item, even if the app version does not yet exist in AppStoreConnect. This is also the case when I log out in the App Store app on the Mac. This makes me think it is using my AppleID which I am logged into in System Settings. Does that sound right?
I would like to be able to remove / delete the cached AppTransactions
- where might I find those on the system?
Thanks for everyone's help!