Skip to content

Instantly share code, notes, and snippets.

@raven
Created October 23, 2017 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raven/85686d11b934a5fd34255ad73a29d912 to your computer and use it in GitHub Desktop.
Save raven/85686d11b934a5fd34255ad73a29d912 to your computer and use it in GitHub Desktop.
PKPaymentAuthorizationResult errors that are of Swift.Error type will crash the host application Radar: 35131271
//
// Copyright © 2017 Peter Goldsmith. All rights reserved.
//
import UIKit
import PassKit
struct BananaError: Error {}
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let request = PKPaymentRequest()
request.countryCode = "US"
request.currencyCode = "USD"
request.supportedNetworks = [PKPaymentNetwork.masterCard]
request.merchantCapabilities = .capability3DS
request.merchantIdentifier = "com.test"
request.paymentSummaryItems = [ PKPaymentSummaryItem(label: "Banana", amount: 30.0)]
if let paymentViewController = PKPaymentAuthorizationViewController(paymentRequest: request) {
paymentViewController.delegate = self
self.present(paymentViewController, animated: true)
}
}
}
extension ViewController: PKPaymentAuthorizationViewControllerDelegate {
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
controller.dismiss(animated: true)
}
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
// The following error type will cause an exception:
// `-[NSXPCEncoder _checkObject:]: This coder only encodes objects that adopt NSSecureCoding (object is of class '_SwiftValue').`
let bananaError: Error = BananaError()
// The following error will not cause the encoding exception.
// let bananaError: Error = NSError(domain: "Banana", code: 0, userInfo: [NSLocalizedDescriptionKey: "Banana"])
let authorisationResult = PKPaymentAuthorizationResult(status: .failure, errors: [bananaError])
completion(authorisationResult)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment