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

JAL*_*JAL 8 storekit nserror ios swift swift2

尝试使用其中一个StoreKit常量时,我​​收到错误"使用未解析的标识符":

SKErrorClientInvalid
SKErrorPaymentCancelled
SKErrorPaymentInvalid
SKErrorPaymentNotAllowed
SKErrorStoreProductNotAvailable
SKErrorUnknown
Run Code Online (Sandbox Code Playgroud)

您的代码可能如下所示:

if transaction.error!.code == SKErrorPaymentCancelled {
    print("Transaction Cancelled: \(transaction.error!.localizedDescription)")
}
Run Code Online (Sandbox Code Playgroud)

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

JAL*_*JAL 19

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

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

SKErrorCode.ClientInvalid
SKErrorCode.CloudServiceNetworkConnectionFailed
SKErrorCode.CloudServicePermissionDenied
SKErrorCode.PaymentCancelled
SKErrorCode.PaymentInvalid
SKErrorCode.PaymentNotAllowed
SKErrorCode.StoreProductNotAvailable
SKErrorCode.Unknown
Run Code Online (Sandbox Code Playgroud)

你应该检查transaction.error.code用enum 检查你的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)
}
Run Code Online (Sandbox Code Playgroud)

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