iOS

In this topic we describe how you can handle most of the SKError's errors e.g.: SKErrorPaymentCancelled, SKErrorInvalidOfferIdentifier, SKErrorUnknown, etc.

Adapty SDK has its own wrapper for all kinds of errors, called AdaptyError. Basically, every error returned by an SDK is AdaptyError. It has two useful properties: originalError and adaptyErrorCode, described below.

originalError

It contains an original error in case you need the original one to work with. Can be SKError, NSError or just general Swift Error. This property is optional since some errors can be generated directly by SDK, like inconsistent or missing data, and won't have original error around which wrapper was initially built.

adaptyErrorCode

This one can be used to handle common issues, like:

  • invalid credentials
  • network errors
  • cancelled payments
  • billing issues
  • invalid receipt
  • and much more

It's pretty easy to check the error for specific codes and react to them accordingly.

Adapty.makePurchase(product: product) { result in
    if result.error?.adaptyErrorCode == .paymentCancelled {
        // purchase was cancelled
        // you can offer discount to your user or remind them later
    }
}

Most common errors and how to handle them

StoreKit errors

AdaptyErrorеCode.paymentCancelled

Corresponds to SKError.Code.paymentCancelled.

Issue:
User cancelled their purchase and was not charged.

Workaround:
No action required, but in terms of the business logic, you can offer a discount to your user or remind them later.

AdaptyErrorCode.cantReadReceipt

Issue:
There is no valid receipt available on the device. Can be an issue during sandbox testing.

Workaround:
In the sandbox, you won't have a valid receipt file until you actually make a purchase, so make sure you did one before accessing it. During sandbox testing also make sure you signed in on a device with a valid Apple sandbox account.

AdaptyErrorCode.invalidOfferIdentifier

Corresponds to SKError.Code.invalidOfferIdentifier.

Issue:
The offer identifier is not valid. For example, you have not set up an offer with that identifier in the App Store, or you have revoked the offer.

Workaround:
Make sure you set up desired offers in AppStore connect and pass a valid offer identifier.

General error list

StoreKit errors

ErrorCodeDescription
unknown0Error code indicating that an unknown or unexpected error occurred.
clientInvalid1Error code indicating that the client is not allowed to perform the attempted action.
paymentCancelled2Error code indicating that the user canceled a payment request.
paymentInvalid3Error code indicating that one of the payment parameters was not recognized by the App Store.
paymentNotAllowed4Error code indicating that the user is not allowed to authorize payments.
storeProductNotAvailable5Error code indicating that the requested product is not available in the store.
cloudServicePermissionDenied6Error code indicating that the user has not allowed access to Cloud service information.
cloudServiceNetworkConnectionFailed7Error code indicating that the device could not connect to the network.
cloudServiceRevoked8Error code indicating that the user has revoked permission to use this cloud service.
privacyAcknowledgementRequired9Error code indicating that the user has not yet acknowledged Apple’s privacy policy for Apple Music.
unauthorizedRequestData10Error code indicating that the app is attempting to use a property for which it does not have the required entitlement.
invalidOfferIdentifier11Error code indicating that the offer identifier is invalid.
invalidSignature12Error code indicating that the signature in a payment discount is not valid.
missingOfferParams13Error code indicating that parameters are missing in a payment discount.
invalidOfferPrice14Error code indicating that the price you specified in App Store Connect is no longer valid.
noProductIDsFound1000No In-App Purchase product identifiers were found.
noProductsFound1001No In-App Purchases were found.
productRequestFailed1002Unable to fetch available In-App Purchase products at the moment.
cantMakePayments1003In-App Purchases are not allowed on this device.
noPurchasesToRestore1004No purchases to restore.
cantReadReceipt1005Can't find a valid receipt.
productPurchaseFailed1006Product purchase failed.
missingOfferSigningParams1007Missing offer signing required params.
fallbackPaywallsNotRequired1008Fallback paywalls are not required.

Network errors

ErrorCodeDescription
notActivated2002You need to be authenticated to perform requests.
badRequest2003Bad request.
serverError2004Server error.
networkFailed2005Network request failed.
decodingFailed2006We could not decode the response.
encodingFailed2009Parameters encoding failed.
missingURL2010Request url is nil.

General errors

ErrorCodeDescription
analyticsDisabled3000We can't handle analytics events, since you've opted it out.
wrongParam3001Wrong parameter was passed.
activateOnceError3005It is not possible to call .activate method more than once.
profileWasChanged3006The user profile was changed during the operation.
persistingDataError3100It was error while saving data.
operationInterrupted9000This operation was interrupted by the system.