Validating receipt from macOS App Extensions?

206 Views Asked by At

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.

0

There are 0 best solutions below