我将 SwiftyStoreKit 与 SwiftUI 和 App 而不是 App Delegate 一起使用,并在控制台中收到此消息:“SwiftyStoreKit.completeTransactions() 应仅在应用启动时调用一次。” 我相信它,因为我在下面的块中调用了 completeTransactions,我可以从 Print 语句中看到,它比以前调用 AppDelegate 的 didFinishLaunching 更频繁。我关注此消息的原因是我在尝试购买时因崩溃而被 App Review 拒绝。我还应该在哪里调用 completeTransactions?
.onChange(of: scenePhase) { newScenePhase in
switch newScenePhase {
case .active:
print("App is active")
SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
for purchase in purchases {
switch purchase.transaction.transactionState {
case .purchased, .restored:
let downloads = purchase.transaction.downloads
if !downloads.isEmpty {
SwiftyStoreKit.start(downloads)
} else if purchase.needsFinishTransaction {
// Deliver content from server, then:
SwiftyStoreKit.finishTransaction(purchase.transaction)
}
print("\(purchase.transaction.transactionState.debugDescription): \(purchase.productId)")
case .failed, .purchasing, .deferred:
break // do nothing
@unknown default:
break // do nothing
}
}
}