1

What am I doing wrong? I deal with Apple Pay (PassKit) and for my app to work and not crash in iOS 11 inside one of my view controllers that conforms to the PKPaymentAuthorizationViewControllerDelegate protocol, this delegate callback must be called.

@available(iOS 11.0, *)
    func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
        // ...
}

I can't compile this in Xcode 8.3. I am using the @available attribute, but it complains about PKPaymentAuthorizationResult being an undeclared type.

Any ideas?

JAL
  • 41,701
  • 23
  • 172
  • 300
Earl Grey
  • 7,426
  • 6
  • 39
  • 59

1 Answers1

0

You need to be using Xcode 9 in order to use PKPaymentAuthorizationResult, as it is only supported on iOS 11 and above. Putting an availability check in your code is not enough, as the PassKit framework shipped with Xcode 8.3 does not have this class.

If you want to use this class in Xcode 8, you need to use a forward declaration of the class, add the header to your project, or use reflection.

JAL
  • 41,701
  • 23
  • 172
  • 300
  • I want my app built in Xcode8 to run on iOS11. ...if it runs on iOS 11 the protocol expects this delegate method implemented. On older OSes it's having a reference to a type it doesn't know. Seems like a trap. – Earl Grey Jun 20 '17 at 16:52