Sarfraz Ali
Sarfraz Ali

Reputation: 3

In App Purchases failed by user on apple ID dialogue

I have a scenario with some steps as follow:

  1. Restore Purchase Method called
  2. Restore Results are fetched
  3. Dialogue for apple ID and password canceled by user
  4. results.restoreFailedPurchases.count > 0
  5. After that restoreFailed result is follow

SKErrorCode(_nsError: Error Domain=SKErrorDomain Code=2 "Cannot connect to iTunes Store" UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store})

How can I get the user info object form that for error message accordingly?

Upvotes: 0

Views: 187

Answers (1)

enc_life
enc_life

Reputation: 5169

You need to unpack the SKError to determine what the underlying error is. In the example you posted, code=2 means the user cancelled.

if let error = error as? SKError {
    switch error.code {
    case .paymentCancelled:
        // Handle user cancelled
    default:
        break
    }
}

SKErrorCode documentation: https://developer.apple.com/documentation/storekit/skerrorcode

Upvotes: 1

Related Questions