O'Reilly logo

iOS 7 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

23.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 23.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 using the latest LLVM compiler, all you have to do is import the relevant umbrella header into your project like so:

#import "AppDelegate.h"
#import <PassKit/PassKit.h>

<# Rest of your code goes here #>

The next thing that we are going to do is declare a private property of type PKPassLibrary in the implementation file of our app delegate. The aforementioned class in PassKit.framework will allow you to interact with the passes that have been added to the device. While you are at it, you will also need to know the keys in the pass.json file that you created in Recipe 23.2 in order to be able to read values such as the departure platform and departure city. So declare these keys as well, all in the implementation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required