1

我正在使用 SwiftyStoreKit Cocoapods 进行应用内购买。GitHub 页面提到 Apple 建议如何在应用程序启动后立即注册事务观察器。Apple 表示:在启动时添加应用程序的观察者可确保它在应用程序的所有启动期间持续存在,从而允许您的应用程序接收所有支付队列通知。

这是链接:https ://github.com/bizz84/SwiftyStoreKit

SwiftyStoreKit 通过completeTransactions()在应用启动时调用来支持这一点:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// see notes below for the meaning of Atomic / Non-Atomic
SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
    for purchase in purchases {
        switch purchase.transaction.transactionState {
        case .purchased, .restored:
            if purchase.needsFinishTransaction {
                // Deliver content from server, then:
                SwiftyStoreKit.finishTransaction(purchase.transaction)
            }
            // Unlock content
        case .failed, .purchasing, .deferred:
            break // do nothing
        }
    }
}
return true }

GitHub 页面继续说:请注意,它completeTransactions()只能在您的代码中调用一次,在application(:didFinishLaunchingWithOptions:).

我无法弄清楚如何实现这一点。有人可以帮忙吗?

4

0 回答 0