5

How a macOS App Extension can validate the app store receipt? That is, to verify whether in-app purchases for the app is valid (and continues to be valid)

Apparently the main bundle points to the App Extension's bundle hence the appStoreReceiptURL property Bundle returns a non-existing receipt file — even when the main app has the App Store receipt file.

For example, the following code prints out the main bundle and app store receipt paths, respectively.

let mainBundle = Bundle.main
print("main bundle path: \(mainBundle.bundleURL)")
print("receipt path: \(String(describing: mainBundle.appStoreReceiptURL))")

When placed inside an App Extension view controller's viewDidLoad, it returns results like these:

main bundle path: file:///Users/${userName}/Library/Developer/Xcode/DerivedData/${projectBuild}/Build/Products/Debug/${mainAppName}.app/Contents/PlugIns/${appExtensionName}.appex/
receipt path: Optional(Contents/_MASReceipt/receipt -- file:///Users/${userName}/Library/Developer/Xcode/DerivedData/${projectBuild}/Build/Products/Debug/${mainAppName}.app/Contents/PlugIns/${appExtensionName}.appex/)

However looking at inside the .appex bundle, the folder Contents/_MASReceipt/ does not exists.

adib
  • 8,285
  • 6
  • 52
  • 91
  • Did you ever solve this? I’m guessing we could copy the receipt to a group container from the main app, but that seems fragile. – Mikey Oct 27 '19 at 12:12
  • 4
    That's what I did. The main app copies the receipt after it passes validation. The extension would re-validate the copy of the receipt whenever it runs. – adib Oct 28 '19 at 13:52
  • It is 2022, Is there a better way by now to access appStoreReceiptURL within the extension? The problem is, the users need to open the main app on a regular basis in order to have an up-to-date receipt information. – Holtwick Mar 30 '22 at 12:21

0 Answers0