justdmitry / PassKitHelper

Helper library for all your Apple PassKit (Apple Wallet, Apple Passbook) needs.
MIT License
26 stars 6 forks source link

How to Expire a Pass #17

Closed safermgmt-bfoster closed 1 year ago

safermgmt-bfoster commented 1 year ago

Hi @justdmitry, Now that I'm able to update the passes using the push notification successfully. I have a request to have the card automatically "expire". This could be through the push request or by setting some expiration date on the card. Is there a way to put an expiration date on the card or even add some sort of watermark on the card saying "cancelled" or "expired"?

I've looked into Apple's documentation, but I was not able to find it.

Any help would be appreciated.

justdmitry commented 1 year ago

https://developer.apple.com/library/archive/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/TopLevel.html#//apple_ref/doc/uid/TP40012026-CH2-SW9

In left menu: Top-Level keys -> Expiration keys

safermgmt-bfoster commented 1 year ago

Thanks for pointing me to this. This works like a charm! For anyone else searching for how to do this, here is some sample code that I hope helps.

 if (!string.IsNullOrEmpty(request.ExpirationDate))
  {
      var expireDate = DateTime.Parse(request.ExpirationDate);
      DateTimeOffset dateTimeOffset = DateTime.SpecifyKind(expireDate, DateTimeKind.Utc);

      pass.ExpirationKeys
          .ExpirationDate(dateTimeOffset);
  }