Skip to content

Instantly share code, notes, and snippets.

@HelloNamiML
Last active August 9, 2020 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HelloNamiML/a8b271c0ddb043728e8f2f4db1a7e275 to your computer and use it in GitHub Desktop.
Save HelloNamiML/a8b271c0ddb043728e8f2f4db1a7e275 to your computer and use it in GitHub Desktop.
Get the App Store receipt from the Bundle for an app.
// Derived from code sample in this article:
// https://developer.apple.com/documentation/storekit/in-app_purchase/validating_receipts_with_the_app_store
// Get the receipt if it's available
if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL,
FileManager.default.fileExists(atPath: appStoreReceiptURL.path) {
do {
let receiptData = try Data(contentsOf: appStoreReceiptURL, options: .alwaysMapped)
let receiptString = receiptData.base64EncodedString(options: [])
print(receiptString)
}
catch { print("Couldn't read receipt data with error: " + error.localizedDescription) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment