Skip to content

Simplified error checking API

Compare
Choose a tag to compare
@bizz84 bizz84 released this 20 Feb 22:01
· 529 commits to master since this release

This release makes it easy to check if the user has canceled a purchase.

This is an API breaking change as the PurchaseError type has been removed in favour of SKError. Clients can now make purchases and check errors like this:

SwiftyStoreKit.purchaseProduct("com.musevisions.SwiftyStoreKit.Purchase1", atomically: true) { result in
    switch result {
    case .success(let product):
        print("Purchase Success: \(product.productId)")
    case .error(let error):
        switch error.code {
        case .unknown: print("Unknown error. Please contact support")
        case .clientInvalid: print("Not allowed to make the payment")
        case .paymentCancelled: break
        case .paymentInvalid: print("The purchase identifier was invalid")
        case .paymentNotAllowed: print("The device is not allowed to make the payment")
        case .storeProductNotAvailable: print("The product is not available in the current storefront")
        case .cloudServicePermissionDenied: print("Access to cloud service information is not allowed")
        case .cloudServiceNetworkConnectionFailed: print("Could not connect to the network")
        }
    }
}

This is in line with: https://developer.apple.com/reference/storekit/skerror.code

Related PR: #138