尝试使用其中一个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) }
如果在iOS 9.3及更高版本上使用StoreKit创建新应用程序,则应检查这些错误代码而不是旧常量.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。