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

尝试使用其中一个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创建新应用程序,则应检查这些错误代码而不是旧常量.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...