Search code examples
iosapple-watchswift5applepaywallet

How can I know if user is add thir card to iPhone wallet or Apple Watch wallet?


I need to hide the add to Apple Wallet button when the user has added their card to the iPhone but keep it on screen when it has been added to the watch only. I am investigating the method

func addPaymentPassViewController(_ controller: PKAddPaymentPassViewController, didFinishAdding pass: PKPaymentPass?, error: Error?)

But I can't find where I can see what device the card has been added to


Solution

  • You can use PKLibrary's passes() function to get the cards that are in the user’s iPhone wallet and then check if the card in question is there. To get the cards in the watch's wallet, use remotePaymentPasses().

    Note that your app has to be entitled to view the card in question, otherwise it will be absent from the returned array. I haven't been able to find much documentation on this so I opened a TSI with Apple to try and get some more information. Someone from the Apple Pay Wallet team got back to me, here's what they said:

    If the app is entitled to view the card it can query it through PKPassLibrary - either using [PKPassLibrary -passesOfType] for cards locally on the device, or [PKPassLibrary -remotePaymentPasses] for cards on paired watches. We recommend apps use these methods to check if their payment passes are already on the device, and use that info to hide the add to Wallet button. Note, this does require the app to be entitled to view the payment pass. This is normally handled by the issuer, so double check with the issuer that they’re setting the associated app IDs of the payment pass to the app.

    Still doesn't totally answer all of my questions, but I would recommend reaching out to the card issuer (that's the next step that I'll be taking).