Akshaykumar Maldhure
Akshaykumar Maldhure

Reputation: 1259

how to restore subscription for old users in SwiftyStorekit?

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))
        }

Upvotes: 2

Views: 1491

Answers (1)

Timothy C.
Timothy C.

Reputation: 639

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")
        }
    }
}

Upvotes: 1

Related Questions