I get the error "Use of unresolved identifier" when trying to use one of these StoreKit constants:
SKErrorClientInvalid
SKErrorPaymentCancelled
SKErrorPaymentInvalid
SKErrorPaymentNotAllowed
SKErrorStoreProductNotAvailable
SKErrorUnknown
Your code may look like this:
if transaction.error!.code == SKErrorPaymentCancelled {
print("Transaction Cancelled: \(transaction.error!.localizedDescription)")
}
What changed? Is there a new module I need to import?
As of iOS 9.3 certain StoreKit constants have been removed from the SDK. See StoreKit Changes for Swift for the full list of changes.
These constants have been replaced in favor of the SKErrorCode
enum and associated values:
SKErrorCode.ClientInvalid
SKErrorCode.CloudServiceNetworkConnectionFailed
SKErrorCode.CloudServicePermissionDenied
SKErrorCode.PaymentCancelled
SKErrorCode.PaymentInvalid
SKErrorCode.PaymentNotAllowed
SKErrorCode.StoreProductNotAvailable
SKErrorCode.Unknown
You should check be checking your transaction.error.code
with the enum's rawValue
. Example:
private func failedTransaction(transaction: SKPaymentTransaction) {
print("failedTransaction...")
if transaction.error?.code == SKErrorCode.PaymentCancelled.rawValue {
print("Transaction Cancelled: \(transaction.error?.localizedDescription)")
}
else {
print("Transaction Error: \(transaction.error?.localizedDescription)")
}
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
}
You should be checking against these error codes rather than the legacy constants if creating a new application using StoreKit on iOS 9.3 and above.
Adding to @JAL answer heres a switch variant
switch (transaction.error!.code) {
case SKErrorCode.Unknown.rawValue:
print("Unknown error")
break;
case SKErrorCode.ClientInvalid.rawValue:
print("Client Not Allowed To issue Request")
break;
case SKErrorCode.PaymentCancelled.rawValue:
print("User Cancelled Request")
break;
case SKErrorCode.PaymentInvalid.rawValue:
print("Purchase Identifier Invalid")
break;
case SKErrorCode.PaymentNotAllowed.rawValue:
print("Device Not Allowed To Make Payment")
break;
default:
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With