swift3 - Accessing code in Swift 3 Error -


new in xcode 8 beta 4, nserror bridged swift error protocol type. affects storekit when dealing failed skpaymenttransactions. ought check sure error didn't occur because transaction cancelled know whether or not show error message user. examining error's code. error instead of nserror, there no code defined. haven't been able figure out how error code error.

this worked in previous version of swift 3:

func failedtransaction(_ transaction: skpaymenttransaction) {     if let transactionerror = transaction.error {         if transactionerror.code != skerrorcode.paymentcancelled.rawvalue {             //show error user         }      }      ... } 

now error error not nserror, code not member.

casting skerror seems working me in xcode 8 , swift 3...

    guard let error = transaction.error as? skerror else {return}     switch error.code {  // https://developer.apple.com/reference/storekit/skerror.code     case .unknown: break     case .paymentcancelled: break     case .clientinvalid: break     case .paymentinvalid: break     case .paymentnotallowed: break     case .cloudservicenetworkconnectionfailed: break     case .cloudservicepermissiondenied: break     case .storeproductnotavailable: break     } 

no need rawvalue.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -