You can create a PKPassLibrary and get a PKPass Array of the passes with the type "payment card".
Then loop through the PKPass Array, check by its primary account identifier or card suffix to see if the card is added already, then change your UI accordingly.
In Swift:
let passLibrary = PKPassLibrary.init()
let paymentPasses = passLibrary.passes(of: .payment) // get PKPass array of payment card
for pass in paymentPasses {
guard let paymentPass = pass.paymentPass else { return }
// or check by suffix paymentPass.primaryAccountNumberSuffix
if paymentPass.primaryAccountIdentifier == "yourCardAccountIdentifier" {
// do something
}
}
In Objective-C:
PKPassLibrary *passLibrary = [[PKPassLibrary alloc] init];
NSArray<PKPass *> *paymentPasses = [passLibrary passesOfType:PKPassTypePayment];
for (PKPass *pass in paymentPasses) {
PKPaymentPass * paymentPass = [pass paymentPass];
if([paymentPass primaryAccountIdentifier] == @"yourCardAccountIdentifier") {
// do something
}
}
And don't forget to include the com.apple.developer.payment-pass-provisioning entitlement in your project. Hope this help you ;)
let library = PKPassLibrary()
let passes = library.passes(of: .payment)
You need to have the authorization to see these passes though. – SuperpowerPKPassLibrary().passes()
returns an empty array, as well asPKPassLibrary().remotePaymentPasses()
. I have my card added manually via Wallet app. – Beckwith