在iOS 9.3 / Xcode 7.3中使用StoreKit常量时使用未解析的标识符 [英] Use of unresolved identifier when using StoreKit constants with iOS 9.3/Xcode 7.3
问题描述
在尝试使用其中一个StoreKit常量时,我收到错误使用未解析的标识符:
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?
推荐答案
从iOS 9.3开始,某些StoreKit常量已从SDK中删除。有关完整列表,请参见针对Swift的StoreKit更改更改。
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.
这些常量已被替换为 SKErrorCode
枚举及相关值:
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
您应该检查使用枚举的 rawValue
检查 transaction.error.code
。示例:
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)
}
如果在iOS 9.3及更高版本上使用StoreKit创建新应用程序,则应检查这些错误代码而不是旧常量。
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.
这篇关于在iOS 9.3 / Xcode 7.3中使用StoreKit常量时使用未解析的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!