20.9. Interacting with Passbook Programmatically

Problem

You want to be able to interact with the installed passes on a user’s device programmatically.

Solution

Include the PassKit.framework into your project and use the PKPassLibrary to find the passes that you are interested in. Passes will be of type PKPass, so using this class you can retrieve information about your passes.

Discussion

Note

As a prerequisite to this recipe, please make sure that you have read Recipe 20.8 and now have an Xcode iOS project that has the appropriate provisioning profile to access your passes in the user’s Passbook library.

Apple has provided the PassKit.framework for iOS developers. Using this framework, you can interact with passes that the user has installed on her devices. To be able to use this framework, you have to first add it to our project. Follow these steps:

  1. On the lefthand side in the Navigator pane, select your project (with the blue icon).

  2. Choose the target that you are building next to the Navigator pane.

  3. On the top of the screen, choose the Build Phases tab.

  4. Move over to and expand the Link Binary With Libraries section and press the + button for it.

  5. In the list of frameworks and libraries that appear on your list, find and choose PassKit.framework and add it to your project, as shown in Figure 20-30.

Adding the PassKit.framework to our target in Xcode

Figure 20-30. Adding the PassKit.framework to our target in Xcode

Now that you have this framework, ...

Get iOS 6 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.