2

I am new in in-app purchase. I am using RevenueCat. I restore purchase like this:

Purchases.shared.restoreTransactions { (purchaserInfo, error) in
}

When there is no purchased product, I want to show to user alert message like this:

You don't have purchases for restore

How can I determine there is no subscribed product?

Shohin
  • 519
  • 8
  • 11

1 Answers1

8

You'd check the purchaserInfo to see if the customer had an active entitlement or purchased the product you're looking for - probably a similar check to what you'd do after a purchase was completed.

Purchases.shared.restoreTransactions { (purchaserInfo, error) in
                
    if let e = error {
        showErrorAlert(message: e.localizedDescription)
        return
    }
    
    if purchaserInfo?.entitlements["premium"]?.isActive != true {
        showErrorAlert(title: "Nothing found to restore ", message: "We couldn't find any active subscriptions to restore. Make sure you're signed in with the correct Apple account and try again.")
        return
    } else {
        showSuccess(title: "Subscription restored ", message: nil)
    }
    
}
enc_life
  • 4,973
  • 1
  • 15
  • 27
  • Hi, I'm new to this framework so I have one question. When I purchase I purchase for a specific package. Imagine my app has several available packages and user buy some of them. How can I allow user restore a specific purchase ? – Tung Vu Duc Aug 31 '21 at 09:40
  • is this also works for aunto renewable subscription ? – Zeeshan Ahmad II May 31 '22 at 11:54