PKPassLibrary Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/PassKit.framework
Availability
Available in iOS 6.0 and later.
Companion guide
Declared in
PKPassLibrary.h

Overview

The PKPassLibrary class provides an interface to the user’s library of passes.

Instances of this class should be used on only a single thread.

Tasks

Accessing Passes

Working with Passes

Class Methods

isPassLibraryAvailable

Returns whether the pass library is available.

+ (BOOL)isPassLibraryAvailable
Return Value

YES if the pass library is available; otherwise, NO.

Discussion

This method is provided because the pass library may be unavailable even if the PKPassLibrary class exists.

Availability
  • Available in iOS 6.0 and later.
Declared In
PKPassLibrary.h

Instance Methods

addPasses:withCompletionHandler:

Presents lightweight UI for adding multiple passes at once.

- (void)addPasses:(NSArray *)passes withCompletionHandler:(void (^)(PKPassLibraryAddPassesStatus status))completion
Parameters
passes

The passes being added.

completion

The completion block called after the user. This block takes the following parameters:

status

Indicates whether the passes were added. If the status is PKPassLibraryShouldReviewPasses, present an instance of PKAddPassesViewController with the same passes, to let the user review and add them.

Discussion

Use this method when the user has already indicated to your app which passes should be added to Passbook—for example, by selecting from a list. The user is asked to confirm the action, but is not shown each individual pass being added, unlike using an instance of PKAddPassesViewController.

Availability
  • Available in iOS 7.0 and later.
Declared In
PKPassLibrary.h

containsPass:

Returns whether the user’s pass library contains a pass.

- (BOOL)containsPass:(PKPass *)pass
Parameters
pass

The pass being queried.

Return Value

YES if the user’s pass library contains the pass; otherwise, NO.

Discussion

This method lets you determine that the pass library contains a pass even though your app wouldn’t be able to read or modify the pass. For example, an email client would not have entitlements to read or write any passes from the library.

Your app can use this method to provide UI indicating whether a pass is already in the library.

Availability
  • Available in iOS 6.0 and later.
Declared In
PKPassLibrary.h

passes

Returns the passes in the user’s pass library

- (NSArray *)passes
Return Value

The passes in the user’s pass library.

Discussion

Your app only has access to certain passes, based on its entitlements. Passes that your app doesn’t have access to are not returned.

The ordering of the passes is not fixed; calling this method multiple times may return the same passes but in a different order.

Availability
  • Available in iOS 6.0 and later.
Declared In
PKPassLibrary.h

passWithPassTypeIdentifier:serialNumber:

Returns the pass with the given pass type identifier and serial number.

- (PKPass *)passWithPassTypeIdentifier:(NSString *)identifier serialNumber:(NSString *)serialNumber
Parameters
identifier

The pass’s pass type identifier.

serialNumber

The pass’s serial number.

Return Value

The pass with the given pass type identifier and serial number, or nil if there is no such pass or if the app doesn’t have the appropriate entitlement.

Availability
  • Available in iOS 6.0 and later.
Declared In
PKPassLibrary.h

removePass:

Removes the pass from the user’s pass library.

- (void)removePass:(PKPass *)pass
Parameters
pass

The pass being removed.

Discussion

This method does nothing if your app doesn’t have the appropriate entitlement.

Availability
  • Available in iOS 6.0 and later.
Declared In
PKPassLibrary.h

replacePassWithPass:

Replaces a pass in the user’s pass library with the given pass.

- (BOOL)replacePassWithPass:(PKPass *)pass
Parameters
pass

The new pass.

Return Value

YES if the pass was replaced successfully; otherwise NO.

Discussion

The new pass replaces the existing pass with the same pass type identifier and serial number. If there is no such pass in the user’s pass library, the replacement fails.

Availability
  • Available in iOS 6.0 and later.
Declared In
PKPassLibrary.h

Constants

Notification Keys

Keys used to get values from the user information dictionary of pass library notifications.

NSString * const PKPassLibraryAddedPassesUserInfoKey;
NSString * const PKPassLibraryRemovedPassInfosUserInfoKey;
NSString * const PKPassLibraryReplacementPassesUserInfoKey;
NSString * const PKPassLibraryPassTypeIdentifierUserInfoKey;
NSString * const PKPassLibrarySerialNumberUserInfoKey;
Constants
PKPassLibraryAddedPassesUserInfoKey

An array of the PKPass objects that were added.

Available in iOS 6.0 and later.

Declared in PKPassLibrary.h.

PKPassLibraryRemovedPassInfosUserInfoKey

An array of dictionaries describing the passes that were removed.

The dictionary contains the keys PKPassLibraryPassTypeIdentifierUserInfoKey and PKPassLibrarySerialNumberUserInfoKey.

Available in iOS 6.0 and later.

Declared in PKPassLibrary.h.

PKPassLibraryReplacementPassesUserInfoKey

An array of the PKPass objects that were replaced.

Available in iOS 6.0 and later.

Declared in PKPassLibrary.h.

PKPassLibraryPassTypeIdentifierUserInfoKey

The pass type identifier of the pass.

Used by the dictionary that is the value of PKPassLibraryRemovedPassInfosUserInfoKey.

Available in iOS 6.0 and later.

Declared in PKPassLibrary.h.

PKPassLibrarySerialNumberUserInfoKey

The serial number of the pass.

Used by the dictionary that is the value of PKPassLibraryRemovedPassInfosUserInfoKey.

Available in iOS 6.0 and later.

Declared in PKPassLibrary.h.

PKPassLibraryAddPassesStatus

Statuses used when adding passes to the pass library.

typedef enum : NSInteger {
   PKPassLibraryDidAddPasses,
   PKPassLibraryShouldReviewPasses,
   PKPassLibraryDidCancelAddPasses,
} PKPassLibraryAddPassesStatus;
Constants
PKPassLibraryDidAddPasses

Status used when passes were sucessfully added.

Available in iOS 7.0 and later.

Declared in PKPassLibrary.h.

PKPassLibraryShouldReviewPasses

Status used when the app should display UI to let the user review the passes.

Available in iOS 7.0 and later.

Declared in PKPassLibrary.h.

PKPassLibraryDidCancelAddPasses

Status used when the user cancelled and the passes were not added.

Available in iOS 7.0 and later.

Declared in PKPassLibrary.h.

Notifications

PKPassLibraryDidChangeNotification

Posted after the pass library has been changed.

The notification is sent by an instance of the PKPassLibrary class. If there are no instances of the class, notifications are not sent. The notification may be sent on any thread or work queue.

The user info dictionary of the notification describes the change. See “Notification Keys” for the keys used.

Availability
Declared In
PKPassLibrary.h