Apple Wallet (formerly Passbook) pass encoding and signing in Swift.
- Modern Swift API
- Allows you to specify custom pass data
- Add other files (images, JSON, etc)
- Manifest generation
- Signing support
- File system managed seamlessly
- Get pass
Data
easily
- macOS 10.12+ or Linux (with zlib development package)
- Xcode 9.0+
- Swift 5.2+
- OpenSSL
Add the following line to your dependencies section of Package.swift
:
.package(url: "https://github.com/aydenp/PassEncoder.git", .upToNextMajor(from: "1.0.0"))
and add "PassEncoder" to your target's dependencies.
// Create our encoder
if let encoder = PassEncoder(passDataURL: directory.appendingPathComponent("pass.json")) {
// Add a nice icon
encoder.addFile(from: directory.appendingPathComponent("icon.png"))
let passData = encoder.encode(signingInfo: (certificate: URL_TO_CERT.PEM, password: CERT_PASSWORD))
// Your archived .pkpass file is in passData as Data
}
Before using the library, you'll also need to set the Apple WWDR certificate URL, which you can read about below.
Heads up! Operations in this library are all synchronous, so it is advisable to run them on a separate
OperationQueue
so that they do not block your thread.
You need to repeat this step for each different passTypeId
you have in your pass.json
.
- Go to the Apple Developer Pass Type IDs page and create your pass type.
- Go to the certificate section and follow the instructions to create a certificate for your pass.
- Download the certificate, and ensure it is named
Certificates.p12
. - Run the following command:
openssl pkcs12 -in Certificates.p12 -out PassCert.pem
. - Your pass certificate is now stored in
PassCert.pem
!
You'll also need to download the Apple Worldwide Developer Relations Intermediate Certificate - G4 file to sign passes.
-
Download the intermediate certificate from here.
-
Import it into Keychain Access (double click it).
-
Find it in Keychain Access, and export it as a .pem file.
-
Set the
PassSigner
's WWDR URL to it in your code.PassSigner.shared.appleWWDRCertURL = URL(fileURLWithPath: PATH_TO_WWDR_CERT.PEM)
To take full advantage of the package, check out the documentation and see all of the methods and variables that are made available to you.
Feel free to contribute to the source code of PassEncoder to make it something even better! Just try to adhere to the general coding style throughout, to make it as readable as possible.
If you find an issue in the code or while using it, create an issue. If you can, you're encouraged to contribute and make a pull request.
This project is licensed under the MIT license. Please make sure you comply with its terms while using it in any way.