在iOS 9.3 / Xcode 7.3中使用StoreKit常量时使用未解析的标识符

前端之家收集整理的这篇文章主要介绍了在iOS 9.3 / Xcode 7.3中使用StoreKit常量时使用未解析的标识符前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
尝试使用其中一个StoreKit常量时,我​​收到错误“使用未解析的标识符”:
  1. SKErrorClientInvalid
  2. SKErrorPaymentCancelled
  3. SKErrorPaymentInvalid
  4. SKErrorPaymentNotAllowed
  5. SKErrorStoreProductNotAvailable
  6. SKErrorUnknown

您的代码可能如下所示:

  1. if transaction.error!.code == SKErrorPaymentCancelled {
  2. print("Transaction Cancelled: \(transaction.error!.localizedDescription)")
  3. }

改变了什么?我需要导入一个新模块吗?

解决方法

从iOS 9.3开始,某些StoreKit常量已从SDK中删除.有关更改的完整列表,请参见 StoreKit Changes for Swift.

这些常量已被替换为SKErrorCode枚举和相关值:

  1. SKErrorCode.ClientInvalid
  2. SKErrorCode.CloudServiceNetworkConnectionFailed
  3. SKErrorCode.CloudServicePermissionDenied
  4. SKErrorCode.PaymentCancelled
  5. SKErrorCode.PaymentInvalid
  6. SKErrorCode.PaymentNotAllowed
  7. SKErrorCode.StoreProductNotAvailable
  8. SKErrorCode.Unknown

您应该检查使用枚举的rawValue检查您的transaction.error.code.例:

  1. private func FailedTransaction(transaction: SKPaymentTransaction) {
  2. print("FailedTransaction...")
  3. if transaction.error?.code == SKErrorCode.PaymentCancelled.rawValue {
  4. print("Transaction Cancelled: \(transaction.error?.localizedDescription)")
  5. }
  6. else {
  7. print("Transaction Error: \(transaction.error?.localizedDescription)")
  8. }
  9. SKPaymentQueue.defaultQueue().finishTransaction(transaction)
  10. }

如果在iOS 9.3及更高版本上使用StoreKit创建新应用程序,则应检查这些错误代码而不是旧常量.

猜你在找的iOS相关文章