23.7. Distributing Passes Using Web Services

Problem

You want users to be able to download your digitally signed passes right from your website.

Solution

In your web pages, create hyperlinks to your .pkpass passes. When users view the web pages on their devices, they can simply tap on those links. Once they tap on the link, Safari will detect that the link leads to a .pkpass file and will hand the link to Passbook, which will display the pass on the website and allow the users to add your passes to their Passbooks.

Discussion

Safari on iOS does not handle direct downloading of .pkpass pass files. In order to let your users download the .pkpass passes, you need to create web pages with hyperlinks in them that point to the .pkpass files. A simple HTML code file that serves a pass.pkpass to the user is displayed here:

<html>
    <header>
        <title>Passbook Site</title>
    </header>
    <body>
        <a href="http://localhost:8888/pass.pkpass">Download your pass here</a>
    </body>
</html>

Note

I have put the link as localhost because I’m running an instance of Apache web server on my installation of OS X. You need to make sure the link in this HTML file makes sense in your web development environment.

Now when the user opens this link in Safari on her device, she will see something similar to Figure 23-17.

Viewing our website in Safari on iOS Simulator

Figure 23-17. Viewing our website in Safari on iOS Simulator

When the user taps on the link, Passbook will pop up ...

Get iOS 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.