Apple Wallet (formerly Passbook) pass encoding and signing in Swift.
Works on iOS! (Sign the manifest on a Mac)
- Modern Swift API
- Allows you to specify custom pass data
- Add other files (images, JSON, etc)
- Manifest generation
- File system managed seamlessly
- Get pass
Data
easily
- iOS 13+
- 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/nivbp7/PassEncoder.git", branch: "master")
and add "PassEncoder" to your target's dependencies.
let data = Data(jsonString.utf8) //create a Data object from a JSON string
// Create our encoder
guard let encoder = PassEncoder(passData: data) else {return}
// Add the required icons and logos
guard let iconPath = Bundle.main.url(forResource: "icon", withExtension: "png"),
let icon2Path = Bundle.main.url(forResource: "icon2", withExtension: "png"),
let logoPath = Bundle.main.url(forResource: "logo", withExtension: "png"),
let logo2Path = Bundle.main.url(forResource: "logo2", withExtension: "png")
else {return}
encoder.addFile(from: iconPath)
encoder.addFile(from: icon2Path)
encoder.addFile(from: logoPath)
encoder.addFile(from: logo2Path)
// Create the manifest
guard let passData = encoder.createManifest() else {return}
* Sign the manifest file on your Mac *
// Add the manifest to the encoder
encoder.addFileWithoutHash(named: "signature", from: data)
// Your archived .pkpass file as Data
let signedData = try self.encoder.archivedData()
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 Root Certificate Authority file to sign passes.
- Download the certificate from here.
- Import it into Keychain Access (double-click it).
- Find it in Keychain Access, and export it as a .pem file.
For documentation of the original repo, check out the documentation and see all of the methods and variables that are made available to you.
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.