how to restore subscription for old users in SwiftyStorekit?

两盒软妹~` 提交于 2020-04-08 18:26:12

问题


In the first version, I was using 3 product id's

  1. Monthly
  2. Three Months
  3. And yearly Subscription

And in my new version of app there are 2 product id's, which are totally new

  1. Month
  2. Year

So my question is, for old users who have already purchased a subscription with old product id's, how he will be able to restore with the new version.

Currently, I m using below code to restore the purchase, but it doesn't restore old product id's.

 SwiftyStoreKit.restorePurchases(atomically: true) { results in
            APP_UTILS.hideHUD()
            for purchase in results.restoredPurchases {
                if purchase.needsFinishTransaction {
                    // Deliver content from server, then:
                    SwiftyStoreKit.finishTransaction(purchase.transaction)
                }
            }
            //self.showAlert(self.alertForRestorePurchases(results))
        }

回答1:


Use this code to restore In App Purchases based on the product ID with SwiftyStoreKit:

SwiftyStoreKit.restorePurchases(atomically: true) { results in
    for product in results.restoredPurchases {

        if product.needsFinishTransaction {
            SwiftyStoreKit.finishTransaction(product.transaction)
        }

        if product.productId == "PASTEPRODUCTID1HERE" {
            print("PRODUCT 1 is restored")
        } else if product.productId == "PASTEPRODUCTID2HERE" {
            print("PRODUCT 2 is restored")
        }
    }
}


来源:https://stackoverflow.com/questions/52628123/how-to-restore-subscription-for-old-users-in-swiftystorekit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!