使用 StoreKit 2 API 完成购买并收到成功且经过验证的 后Product.PurchaseResult,本地收据要么仍然为空,要么未随成功购买而更新(在沙盒环境中)。理想情况下,我不再需要它,但我们的服务器端实现当前需要编码的收据数据,因此对于我当前的用例,我仍然需要访问它。
我的购买流程是这样的:
let purchaseResult = try await product.purchase(options: purchaseOptions)
switch purchaseResult {
case .success(let verification):
let transaction = try checkVerified(verification)
...
guard let receiptPath = Bundle.main.appStoreReceiptURL?.path else {
throw Error.missingReceipt
}
let receiptData = NSData(contentsOfFile: receiptPath) // Receipt data is nil here
let receiptString = receiptData?.base64EncodedString(options: .endLineWithLineFeed) ?? ""
...
// Handle server logic
...
await transaction.finish()
case ...
...
}
Run Code Online (Sandbox Code Playgroud)
我的理解是,使用 StoreKit 2 API 时仍应生成收据数据 - 有没有办法保证在成功完成购买后和交易处理期间填充收据数据?