New in Xcode 8 beta 4, NSError
is bridged to the Swift Error
protocol type. This affects StoreKit when dealing with failed SKPaymentTransaction
s. You ought to check to be sure the error didn't occur because the transaction was cancelled to know whether or not to show an error message to the user. You do this by examining the error's code
. But with Error
instead of NSError
, there is no code
defined. I haven't been able to figure out how to properly get the error code from Error
.
This worked in the previous version of Swift 3:
func failedTransaction(_ transaction: SKPaymentTransaction) {
if let transactionError = transaction.error {
if transactionError.code != SKErrorCode.paymentCancelled.rawValue {
//show error to user
}
}
...
}
Now that error
is an Error
not NSError
, code
is not a member.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…