Xcode 8 beta 4中的新功能NSError与Swift Error协议类型相连.这会在处理失败的SKPaymentTransactions 时影响StoreKit .您应该检查以确保没有发生错误,因为事务被取消以了解是否向用户显示错误消息.你通过检查错误来做到这一点code.但有了Error代替NSError,没有code定义.我无法弄清楚如何正确获取错误代码Error.
这在Swift 3的早期版本中有效:
func failedTransaction(_ transaction: SKPaymentTransaction) {
if let transactionError = transaction.error {
if transactionError.code != SKErrorCode.paymentCancelled.rawValue {
//show error to user
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
现在error是Error不是NSError,code是不是成员.