StoreKit2 用于验证付费应用程序的购买
我在 Mac App Store 中有一个预付费应用程序,我想通过验证收据来验证用户是否合法购买了该应用程序。 StoreKit2 框架(随 iOS15/macOS12 引入)声称有一种简单的方法可以做到这一点,但我无法让它工作。从我看到的文档来看,我相信 Transaction.currentEntitlements
调用只会返回 IAP 和订阅的交易。还有另一种方法 Transaction.all
表示它“返回所有交易历史记录”,但尚不清楚它是否应包含付费应用程序的交易。我尝试运行该应用程序(附加了 Xcode 调试器),但没有得到任何结果。
我是这样称呼它的:
for await result in Transaction.all {
guard case .verified(let transaction) = result else { continue }
print("verified product = \(transaction.productID)")
}
但是当我运行它时,我在控制台中没有打印任何内容。 这是 文档 关于 Transaction.all 的内容:
此序列返回当前用户的交易历史记录 当您访问序列时。该序列发出有限数量的 交易。如果App Store为用户处理新交易 当您访问此序列时,新交易会出现在 事务监听器,更新。交易记录没有 包括消耗品成品或非更新成品 订阅、回购的非消耗产品或订阅, 或恢复购买。
即使读完本文后,我也不能 100% 确定付费应用交易是否应该显示在交易历史记录中。
谁能澄清这一点吗?如果它应该在历史记录中显示付费应用程序,那么在开发过程中(在它实际进入应用程序商店之前)进行测试的最佳方法是什么?
I have a paid-up-front app in the Mac App Store, and I want to verify that the user purchased the app legitimately by verifying the receipt. The StoreKit2 framework (introduced with iOS15/macOS12) claims to have an easy way to do this, but I can't get it to work. From the documentation I've seen, I believe the Transaction.currentEntitlements
call will only return transactions for IAP and subscriptions. There is another method Transaction.all
which says it "returns all transaction history", but it's not clear if it should include transactions for paid apps. I've tried running the app (with Xcode debugger attached) I get no results.
Here's how I'm calling it:
for await result in Transaction.all {
guard case .verified(let transaction) = result else { continue }
print("verified product = \(transaction.productID)")
}
But I get nothing printed in the console when I run this.
This is what the documentation says about Transaction.all:
This sequence returns the user’s transaction history current to the
moment you access the sequence. The sequence emits a finite number of
transactions. If the App Store processes new transactions for the user
while you’re accessing this sequence, the new transactions appear in
the transaction listener, updates. The transaction history doesn’t
include finished consumable products or finished non-renewing
subscriptions, repurchased non-consumable products or subscriptions,
or restored purchases.
Even after reading this, I'm not 100% sure if paid apps transactions should show up in the transaction history or not.
Can anyone clarify this? If it should show paid apps in the history, what's the best way to test this out during development (before it's actually in the App Store)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论