验证来自 macOS 应用扩展的收据?

adi*_*dib 5 macos receipt-validation swift macos-app-extension

macOS应用扩展如何如何验证应用商店收据?即验证应用内购买是否有效(并且持续有效)

\n\n

显然,主捆绑包指向应用程序扩展的捆绑包,因此appStoreReceiptURL属性Bundle也会返回不存在的收据文件 \xe2\x80\x94 。

\n\n

例如,以下代码分别打印出主包和应用程序商店收据路径。

\n\n
let mainBundle = Bundle.main\nprint("main bundle path: \\(mainBundle.bundleURL)")\nprint("receipt path: \\(String(describing: mainBundle.appStoreReceiptURL))")\n
Run Code Online (Sandbox Code Playgroud)\n\n

当放置在应用程序扩展视图控制器内时viewDidLoad,它返回如下结果:

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

然而,看看.appex捆绑包的内部,文件夹Contents/_MASReceipt/不存在。

\n