malinchhan
malinchhan

Reputation: 767

Generate pass dynamically

I created a pass statically by typing command line in order to create pass.pkpass. I also use web service in MAMP. How to generate a pass dynamically ? and where is pass.pkpass stored ?

Upvotes: 3

Views: 2272

Answers (1)

PassKit
PassKit

Reputation: 12581

To generate the pass dynamically, you will need code that will:

  • Retrieve all the dynamic data that you want to put into the pass
  • Create a pass.json file containing the dynamic pass data and compute its SHA1 hash
  • Gather the pass assets (images, locale strings, etc.) and compute their SHA1 hash
  • Assemble the manifest file (list of files in the .pkpass bundle and their SHA1 hashes)
  • Sign the manifest file with your PassID Certificate and include the Apple WWDR cert
  • Zip all of the assets up into a .pkpass bundle
  • Serve the .pkpass bundle with the correct MIME type
  • Cleanup any temporary folders/files you use in the above process

You may also need code to:

  • Generate random tokens for the serialNumber and authenticationToken
  • Record the pass details in a database

As for where the .pkpass files go, this is entirely up to you. You can either store them or delete them once they have been served to the device. Since the code that you will need can recreate the .pkpass bundle, and since your web service will send a 304 response to a device that already has the latest version of the pass, there is little value in keeping these files on your server.

If you are using MAMP, then this PHP Library is a good place to start.

Upvotes: 3

Related Questions