尝试在应用启动时使用应用程序(:didFinishLaunchingWithOptions :)调用函数

时间:2018-04-09 15:00:01

标签: swift xcode delegates storekit swiftystorekit

我正在使用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:)

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

0 个答案:

没有答案