Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/improve error handling #138

Merged
merged 7 commits into from Feb 20, 2017
Merged

Conversation

bizz84
Copy link
Owner

@bizz84 bizz84 commented Feb 20, 2017

This PR streamlines error handling. See related issue: #122

This makes it much easier to check all possible errors that can happen during a purchase:

  • clientInvalid: Not allowed to make the payment
  • paymentCancelled: The user has cancelled the payment
  • paymentInvalid: The purchase identifier was invalid
  • paymentNotAllowed: In-app purchases have been disabled for the device
  • storeProductNotAvailable: The product is not available in the current storefront
  • cloudServicePermissionDenied: Access to cloud service information is not allowed
  • cloudServiceNetworkConnectionFailed: Could not connect to the network
  • unknown: anything else

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

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

@bizz84 bizz84 merged commit ff7a46d into develop Feb 20, 2017
@bizz84 bizz84 deleted the feature/improve-error-handling branch February 22, 2017 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant