尝试使用其中一个StoreKit常量时,我收到错误“使用未解析的标识符”:
- SKErrorClientInvalid
- SKErrorPaymentCancelled
- SKErrorPaymentInvalid
- SKErrorPaymentNotAllowed
- SKErrorStoreProductNotAvailable
- SKErrorUnknown
您的代码可能如下所示:
- if transaction.error!.code == SKErrorPaymentCancelled {
- print("Transaction Cancelled: \(transaction.error!.localizedDescription)")
- }
改变了什么?我需要导入一个新模块吗?
解决方法
从iOS 9.3开始,某些StoreKit常量已从SDK中删除.有关更改的完整列表,请参见
StoreKit Changes for Swift.
这些常量已被替换为SKErrorCode
枚举和相关值:
- SKErrorCode.ClientInvalid
- SKErrorCode.CloudServiceNetworkConnectionFailed
- SKErrorCode.CloudServicePermissionDenied
- SKErrorCode.PaymentCancelled
- SKErrorCode.PaymentInvalid
- SKErrorCode.PaymentNotAllowed
- SKErrorCode.StoreProductNotAvailable
- SKErrorCode.Unknown
您应该检查使用枚举的rawValue检查您的transaction.error.code.例:
- 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)
- }