标签: storekit2

StoreKit2 Transaction.currentEntitlements 不返回自动续订

如何返回Transaction.currentEntitlements应用程序关闭时发生的订阅自动续订交易?


我已经在 macOS 应用程序中实现了自动续订订阅。

我有一个可以在和StoreManager上创建听众的Transaction.currentEntitlementsTransaction.updates

如果在应用程序运行时续订订阅,Transaction.updates则会按预期接收最新交易。

但是,当应用程序未运行时自动发生续订时,重新打开应用程序时Transaction.currentEntitlements不会返回续订交易。

按照以下步骤进行重现:

  • 启动应用程序并购买自动续订订阅
  • 杀死该应用程序
  • 等待订阅到期自动续订(测试时可以设置每月30秒续订)
  • 重新启动应用程序
  • Transaction.currentEntitlements什么也不返回。

在应用程序启动时检查StoreKit Transactions调试窗口,应用程序关闭时发生的续订交易显示为“未完成”。

在此输入图像描述

未完成的交易是指未返回的交易。

如果在应用程序运行时再次续订订阅,则会Transaction.updates触发侦听器,并返回新的续订以及任何未完成的事务。

这是来自的相关代码StoreManager

@MainActor
class StoreManager: ObservableObject {
    
    var updates: Task<Void, Never>? = nil
    var transactions: Task<Void, Never>? = nil

    init() {
        updates = updatesListenerTask()
        transactions = transactionsListenerTask()
    }

    @Published private (set) var transaction: StoreKit.Transaction?
    
    func updatesListenerTask() -> Task<Void, Never> {
        Task.detached(priority: .background) {
            for …
Run Code Online (Sandbox Code Playgroud)

storekit swift storekit2

8
推荐指数
0
解决办法
1612
查看次数

How to deal with StoreKit 2 on Airplane mode or offline?

I'm trying to add/manage my first in-app purchase (non-consumable) on my iOS app and I just discovered that StoreKit 2 doesn't work well offline.

These past days, I used to display (or not) the premium features based on store.purchasedItems.isEmpty but this doesn't work at all on Airplane mode.

I mean, I understand that some parts of my Store file can't be accessible offline. The fetch request from the App Store can only works online, for example. But I didn't expected …

storekit in-app-purchase app-store-connect swiftui storekit2

4
推荐指数
1
解决办法
852
查看次数