自动续订订阅深入理解

时间:2018-11-23 07:34:15

标签: swift in-app-purchase subscription in-app-subscription auto-renewable

我正在使用SwiftyStoreKit在我的应用程序中实现带有自动续订订阅的应用程序内购买。我只需要了解一些事情。

首先这是我的代码:

func verifyPurchase(product: SKProduct) {
    NetworkAcivityIndicatorManager.NetworkOperationStaterd()
    let appleValidator = AppleReceiptValidator(service: .sandbox, sharedSecret: SharedSecret)
    SwiftyStoreKit.verifyReceipt(using: appleValidator) { (result) in
        NetworkAcivityIndicatorManager.NetworkOperationFinished()
        print("NEW IAP: Verify Purchase")

        switch result {
        case .success(receipt: let receipt):
            if product.productIdentifier == self.bundleID + "." + RegisteredPurchases.Subscription.rawValue {
                let purchaseResult: VerifySubscriptionResult = SwiftyStoreKit.verifySubscription(ofType: .autoRenewable, productId: product.productIdentifier, inReceipt: receipt, validUntil: Date())
                print("NEW IAP: Verify Subscription: \(purchaseResult)")

                switch purchaseResult {
                    case .expired(let expiresDate):
                        print("NEW IAP: Expired: \(expiresDate)")
                    case .purchased(let expiresDate):
                        print("NEW IAP: Purchased: \(expiresDate)")
                    case .notPurchased:
                        print("NEW IAP: Not Purchased")
                }

            } else {
                let purchaseResult = SwiftyStoreKit.verifyPurchase(productId: product.productIdentifier, inReceipt: receipt)
                print("NEW IAP: Verify Purchase: \(purchaseResult)")
            }
        case .error(let error):
            print("NEW IAP: Verify Purchase: \(error.localizedDescription)")
        }
    }
}

第一次购买后,我在收据过期之前还有3分钟的时间(沙盒),但这对生产意味着什么?我需要续订订阅还是对其进行一些操作?

                switch purchaseResult {
                    case .expired(let expiresDate):
                        print("NEW IAP: Expired: \(expiresDate)")
                    case .purchased(let expiresDate):
                        print("NEW IAP: Purchased: \(expiresDate)")
                    case .notPurchased:
                        print("NEW IAP: Not Purchased")
                }

如果购买了购买结果,那么我不需要做任何事情,如果没有购买,则需要购买它,如果过期了,我需要致电刷新收据吗?不再次购买?

func refreshReceipt() {
    SwiftyStoreKit.fetchReceipt(forceRefresh: true) { (result) in
        print("NEW IAP: Receipt Refreshed: \(result)")
    }
}

0 个答案:

没有答案