Distributing Passes
After you have created a signed, compressed pass bundle, getting it into Wallet is easy. Mail and Safari support passes in iOS 6 and later and in macOS v10.8.2 and later, so you can use them to distribute passes by email or from a website. In iOS, they add passes to the pass library directly. In macOS, they use iCloud to add passes to the user’s iOS devices.
The advantage of sending passes as an email attachment is simplicity. When users view the email, the pass appears and can be added to their pass library. During development, this is an easy way to get a pass onto your device. The disadvantage is that you can’t interact with the pass-installation process. For example, an email can’t present an alternative representation for older devices that don’t support passes.
Hosting passes on your web server gives you more control over the user experience, but it’s less simple. You can give your users a link to a landing page that lets them add the pass to their pass library. This page can also offer a representation of the pass in older formats, such as PDF. This landing page also gives you a place to ask the user to log in if needed.
Using your own app to install passes is appropriate when your app provides a richer experience by integrating with your systems and business. For information about how your app can interact with passes, see Interacting with Passes in Your App.
Your website and email can use the Add to Wallet badge to give your users a visual queue to add the pass to Wallet. For more information, see the Add to Apple Wallet Badge section of the Developer website. To create buttons for your app, use the PKAddPassButton
class.
Programmatically Adding Passes
Before attempting to add passes to Wallet, see whether the device supports adding passes. Call the PKAddPassesViewController
class’s canAddPasses
method. If this method returns YES
true
, add your passes.
To add a single pass, download the signed, encrypted package, and instantiate a PKPass
object using the downloaded data. Next, create a PKAddPassesViewController
instance for the pass object. Present this view controller to the user.
This view controller shows the user your pass. The user can then approve or reject the pass.
Alternatively, you can bulk-add multiple passes, for example, when adding boarding passes for a multileg flight. Simply create an array of PKPass
objects, and then present these passes to the user by calling the PKPassLibrary
class’s addPasses:withCompletionHandler:
method. This method presents a lightweight interface, letting the user review and approve all the passes in the array.
Due to the name change, apps running in iOS 9 and later should use buttons that refer to Wallet. Apps running in iOS 8 or earlier should use buttons that refer to Passbook. To create a Wallet-branded button, use the PKAddPassButton
class. For Passbook branded buttons, use the resources described in Passbook for Developers at the Developer website.
Working with Web Views
If your pass is already available on the web, you may want to present that content directly in your app. There are several different ways to present web content from an iOS app. Some automatically handle pass files. Others require additional steps to download and process the pass.
Here are three recommended ways to present web content from an app:
Open the web page in Safari, transferring control from your app to the Safari app.
Present the content using an
SFSafariViewController
view controller.Show the content in a
WKWebView
instance.
Both the Safari app and the Safari view controller can import the pass files directly into the pass library.
If you want to load a file using a web view, you must detect the request, download the pass, and programmatically add the pass yourself.
For WKWebView
, perform the following steps:
In your
WKNavigationDelegate
object’swebView:decidePolicyForNavigationResponse:decisionHandler:
method, check the response’s MIME type.If the mime type is
application/vnd.apple.pkpass
, begin asynchronously downloading the pass from your server, and then call the delegate method’s decision handler. PassWKNavigationResponsePolicyCancel
to keep the web view from loading the pass.After the download completes, programatically add the pass using a
PKAddPassesViewController
instance. For more information, see Programmatically Adding Passes.
Copyright © 2018 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2018-01-16