在iOS 9.3/Xcode 7.3中使用StoreKit常量时使用未解析标识符
尝试使用以下StoreKit常量之一时,出现错误“使用未解析标识符”:在iOS 9.3/Xcode 7.3中使用StoreKit常量时使用未解析标识符,ios,swift,swift2,storekit,nserror,Ios,Swift,Swift2,Storekit,Nserror,尝试使用以下StoreKit常量之一时,出现错误“使用未解析标识符”: SKErrorClientInvalid SKErrorPaymentCancelled SKErrorPaymentInvalid SKErrorPaymentNotAllowed SKErrorStoreProductNotAvailable SKErrorUnknown 您的代码可能如下所示: if transaction.error!.code == SKErrorPaymentCancelled { pr
SKErrorClientInvalid
SKErrorPaymentCancelled
SKErrorPaymentInvalid
SKErrorPaymentNotAllowed
SKErrorStoreProductNotAvailable
SKErrorUnknown
您的代码可能如下所示:
if transaction.error!.code == SKErrorPaymentCancelled {
print("Transaction Cancelled: \(transaction.error!.localizedDescription)")
}
switch (transaction.error!.code) {
case StoreKit.SKErrorCode.Unknown.rawValue:
print("Unknown error")
break;
}
什么改变了?是否需要导入新模块?从iOS 9.3开始,某些StoreKit常量已从SDK中删除。有关更改的完整列表,请参见 这些常量已被替换为有利于枚举和相关值:
SKErrorCode.ClientInvalid
SKErrorCode.CloudServiceNetworkConnectionFailed
SKErrorCode.CloudServicePermissionDenied
SKErrorCode.PaymentCancelled
SKErrorCode.PaymentInvalid
SKErrorCode.PaymentNotAllowed
SKErrorCode.StoreProductNotAvailable
SKErrorCode.Unknown
您应该使用枚举的
rawValue
检查您的事务.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创建新的应用程序,您应该检查这些错误代码,而不是旧的常量。添加到@JAL answer中有一个交换机变体
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;
}
以上所有答案对我都不起作用。解决这个问题的办法是将StoreKit预先准备好,然后放在SKError上 我的开关看起来像这样:
if transaction.error!.code == SKErrorPaymentCancelled {
print("Transaction Cancelled: \(transaction.error!.localizedDescription)")
}
switch (transaction.error!.code) {
case StoreKit.SKErrorCode.Unknown.rawValue:
print("Unknown error")
break;
}
不知道为什么。“您应该检查您的事务。使用其中一个值出错”我认为这是不可能的。SKErrorCode不是NSError。仅.code反对.rawValue对我有效。@谢谢,我会进行编辑。这对你有用吗
if transaction.error?.code==SKErrorCode.PaymentCancelled.rawValue{…}
我使用了一个switch语句,但是yes.code from.rawValue可以工作(请参见下面的答案)在引用SKErrorCode
struct时发生了什么错误?听起来好像有名称空间冲突。