iOS Developer Library — Pre-Release

Developer

PassKit Framework Reference PKPassLibrary Class Reference

Options
Deployment Target:

On This Page
Language:

PKPassLibrary

Inheritance


Conforms To


Import Statement


Swift

import PassKit

Objective-C

@import PassKit;

Availability


Available in iOS 6.0 and later.

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

The PKPassLibrary is not thread-safe. Use instances of this class only on a single thread.

  • Indicates whether the pass library is available.

    Declaration

    Swift

    class func isPassLibraryAvailable() -> Bool

    Objective-C

    + (BOOL)isPassLibraryAvailable

    Return Value

    YEStrue if the pass library is available; otherwise, NOfalse.

    Discussion

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

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 6.0 and later.

  • Returns the passes in the user’s pass library to which the app has access.

    Declaration

    Swift

    func passes() -> [AnyObject]!

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func passWithPassTypeIdentifier(_ identifier: String!, serialNumber serialNumber: String!) -> PKPass!

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 6.0 and later.

  • Returns the passes of the specified pass type.

    Declaration

    Swift

    func passesOfType(_ passType: PKPassType) -> [AnyObject]!

    Objective-C

    - (NSArray *)passesOfType:(PKPassType)passType

    Parameters

    passType

    One of the pass types in PKPassType.

    Return Value

    An array of passes of the specified type.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 8.0 and later.

  • Presents lightweight UI for adding multiple passes at once.

    Declaration

    Swift

    func addPasses(_ passes: [AnyObject]!, withCompletionHandler completion: ((PKPassLibraryAddPassesStatus) -> Void)!)

    Objective-C

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

    Parameters

    passes

    The passes being added.

    completion

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

    status

    Indicates whether the passes were added. If the user selects to review the passes, this status is set to PKPassLibraryShouldReviewPasses. In this case, you must present an instance of PKAddPassesViewController to let the user review and add the passes.

    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. If you want to let the user review and select individual passes from an array of passes, use an instance of PKAddPassesViewController instead.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 7.0 and later.

  • Indicates whether the user’s pass library contains the specified pass.

    Declaration

    Swift

    func containsPass(_ pass: PKPass!) -> Bool

    Objective-C

    - (BOOL)containsPass:(PKPass *)pass

    Parameters

    pass

    The pass being queried.

    Return Value

    YEStrue if the user’s pass library contains the pass; otherwise, NOfalse.

    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 a UI indicating whether a pass is already in the library.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 6.0 and later.

  • Removes the pass from the user’s pass library.

    Declaration

    Swift

    func removePass(_ pass: PKPass!)

    Objective-C

    - (void)removePass:(PKPass *)pass

    Parameters

    pass

    The pass being removed.

    Discussion

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

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func replacePassWithPass(_ pass: PKPass!) -> Bool

    Objective-C

    - (BOOL)replacePassWithPass:(PKPass *)pass

    Parameters

    pass

    The new pass.

    Return Value

    YEStrue if the pass was replaced successfully; otherwise NOfalse.

    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.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 6.0 and later.

  • Activates a payment pass using the provided activation code.

    Declaration

    Swift

    func activatePaymentPass(_ paymentPass: PKPaymentPass!, withActivationCode activationCode: String!, completion completion: ((Bool, NSError!) -> Void)!)

    Objective-C

    - (void)activatePaymentPass:(PKPaymentPass *)paymentPass withActivationCode:(NSString *)activationCode completion:(void (^)(BOOL success, NSError *error))completion

    Parameters

    paymentPass

    The payment pass being activated.

    activationCode

    The activation code.

    completion

    The completion block called after activation.

    This block takes the following parameters:

    success

    YEStrue if the pass was authorized; otherwise NOfalse.

    error

    If success is NOfalse, a description of the error.

    Discussion

    The pass must already be provisioned, and it must currently be in the PKPaymentPassActivationStateRequiresActivation state.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 8.0 and later.

  • Activates a payment pass using the provided activation code.

    Declaration

    Swift

    func activatePaymentPass(_ paymentPass: PKPaymentPass!, withActivationData activationData: NSData!, completion completion: ((Bool, NSError!) -> Void)!)

    Objective-C

    - (void)activatePaymentPass:(PKPaymentPass *)paymentPass withActivationData:(NSData *)activationData completion:(void (^)(BOOL success, NSError *error))completion

    Parameters

    paymentPass

    The payment pass being activated.

    activationData

    The cryptographic one-time password.

    This data is Base64 encoded and then sent to the payment network. The framework treats this as an opaque value.

    completion

    The completion block called after activation.

    This block takes the following parameters:

    success

    YEStrue if the pass was authorized; otherwise NOfalse.

    error

    If success is NOfalse, a description of the error.

    Discussion

    The pass must already be provisioned, and it must currently be in the PKPaymentPassActivationStateRequiresActivation state.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 8.0 and later.

  • Indicates whether the device supports adding payment passes.

    Declaration

    Swift

    class func isPaymentPassActivationAvailable() -> Bool

    Objective-C

    + (BOOL)isPaymentPassActivationAvailable

    Return Value

    YEStrue if the device supports adding payment passes; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 8.0 and later.

  • Opens the user interface to set up credit cards for Apple Pay.

    Declaration

    Swift

    func openPaymentSetup()

    Objective-C

    - (void)openPaymentSetup

    Discussion

    Use this method to move users to the interface for adding credit cards. This method will transfer control to the Passbook app on iPhone or the Settings app on iPad. On devices that do not support Apple Pay, this method does nothing.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 8.3 and later.

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

    Declaration

    Swift

    let PKPassLibraryAddedPassesUserInfoKey: String let PKPassLibraryRemovedPassInfosUserInfoKey: String let PKPassLibraryReplacementPassesUserInfoKey: String let PKPassLibraryPassTypeIdentifierUserInfoKey: String let PKPassLibrarySerialNumberUserInfoKey: String

    Objective-C

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

    Constants

    • PKPassLibraryAddedPassesUserInfoKey

      PKPassLibraryAddedPassesUserInfoKey

      An array of the PKPass objects that were added.

      Available in iOS 6.0 and later.

    • PKPassLibraryRemovedPassInfosUserInfoKey

      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.

    • PKPassLibraryReplacementPassesUserInfoKey

      PKPassLibraryReplacementPassesUserInfoKey

      An array of the PKPass objects that were replaced.

      Available in iOS 6.0 and later.

    • PKPassLibraryPassTypeIdentifierUserInfoKey

      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.

    • PKPassLibrarySerialNumberUserInfoKey

      PKPassLibrarySerialNumberUserInfoKey

      The serial number of the pass.

      Used by the dictionary that is the value of PKPassLibraryRemovedPassInfosUserInfoKey.

      Available in iOS 6.0 and later.

  • Statuses used when adding passes to the pass library.

    Declaration

    Swift

    enum PKPassLibraryAddPassesStatus : Int { case DidAddPasses case ShouldReviewPasses case DidCancelAddPasses }

    Objective-C

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

    Constants

    • DidAddPasses

      PKPassLibraryDidAddPasses

      Status used when passes were successfully added.

      Available in iOS 7.0 and later.

    • ShouldReviewPasses

      PKPassLibraryShouldReviewPasses

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

      Available in iOS 7.0 and later.

    • DidCancelAddPasses

      PKPassLibraryDidCancelAddPasses

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

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 7.0 and later.

  • 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.

    Import Statement

    Objective-C

    @import PassKit;

    Swift

    import PassKit

    Availability

    Available in iOS 6.0 and later.