iOS 15 引入了 StoreKit 2。我正在研究它,看看是否可以在我现有的应用程序中采用它,但我不知道该怎么做。特别是,我不知道如何实现所需的恢复功能(例如,如果用户删除了我的应用程序)。
我想我们应该使用Transaction.latest(for:)
?是对的吗?
但在我的测试中,如果用户使用 StoreKit 1 进行了购买,则该调用将返回nil
. 这是真的?或者,如果我做错了,从 StoreKit 1 迁移到 StoreKit 2 的正确方法是什么,以及我们如何处理恢复?
小智 16
在Apple的SKDemo中,他们这样做
Button("Restore Purchases", action: {
async {
//This call displays a system prompt that asks users to authenticate with their App Store credentials.
//Call this function only in response to an explicit user action, such as tapping a button.
try? await AppStore.sync()
}
})
Run Code Online (Sandbox Code Playgroud)
我个人想知道是否成功,所以我将其包装在一个方法中
func restore() async -> Bool {
return ((try? await AppStore.sync()) != nil)
}
Run Code Online (Sandbox Code Playgroud)
并相应地弹出警报
Pau*_*w11 15
您可以进行迭代Transaction.currentEntitlements
以获得所有有效订阅和以前购买的非消耗产品。
如果您在启动时检查此集合,您可以静默恢复任何以前的购买,无需用户交互。
归档时间: |
|
查看次数: |
4965 次 |
最近记录: |