当尝试使用以下StoreKit常量之一时,我得到了“使用未解析标识符”的错误:
SKErrorClientInvalid
SKErrorPaymentCancelled
SKErrorPaymentInvalid
SKErrorPaymentNotAllowed
SKErrorStoreProductNotAvailable
SKErrorUnknown
代码可能如下所示:
if transaction.error!.code == SKErrorPaymentCancelled {
print("Transaction Cancelled: \(transaction.error!.localizedDescription)")
}
什么改变了?我需要导入一个新模块吗?
发布于 2016-03-22 14:25:56
截至iOS 9.3,某些StoreKit常量已从SDK中删除。有关更改的完整列表,请参见Swift的StoreKit更改。
这些常量已被替换成SKErrorCode
枚举和相关值:
SKErrorCode.ClientInvalid
SKErrorCode.CloudServiceNetworkConnectionFailed
SKErrorCode.CloudServicePermissionDenied
SKErrorCode.PaymentCancelled
SKErrorCode.PaymentInvalid
SKErrorCode.PaymentNotAllowed
SKErrorCode.StoreProductNotAvailable
SKErrorCode.Unknown
您应该检查您的transaction.error.code
和枚举的rawValue
。示例:
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)
}
如果使用StoreKit在iOS 9.3和更高版本上创建新应用程序,您应该检查这些错误代码而不是遗留常量。
发布于 2016-03-23 14:02:29
在@JAL应答中添加一个开关变量
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;
}
发布于 2016-11-28 02:36:17
以上的答案对我都没有用。解决这个问题的方法是把StoreKit放在SKError的前面。
我的开关看起来是这样的:
switch (transaction.error!.code) {
case StoreKit.SKErrorCode.Unknown.rawValue:
print("Unknown error")
break;
}
不知道为什么。
https://stackoverflow.com/questions/36157086
复制相似问题