Use passninja-swift as an iOS package.
- Select
File
/Swift Packages
/Add Package Dependency…
from the menu. - Paste
https://github.com/flomio/passninja-swift.git
. - Follow the steps and select from main branch.
Use this class to init a Passninja
object. Make sure to
pass your user credentials to make any authenticated requests.
import PassNinjaSwift
let accountId = "**your-account-id**"
let apiKey = "**your-api-key**"
PassNinja.initWith(accountId: accountId, apiKey: apiKey)
We've placed our demo user API credentials in this example. Replace it with your actual API credentials to test this code through your PassNinja account and don't hesitate to contact PassNinja with our built in chat system if you'd like to subscribe and create your own custom pass type(s).
For more information on how to use passninja-swift
once it loads, please refer to
the PassNinja Swift API reference
This library currently supports methods for creating, getting, updating, and deleting passes via the PassNinja api. The methods are outlined below.
PassClient.shared.createPass(pass: PassRequest(passType: "demo.coupon", pass: [discount: '50%', memberName: 'John']), onSuccess: { (pass) in
print(pass.urls as Any)
print(pass.passType as Any)
print(pass.serialNumber as Any)
print(pass.pass?.logoText as Any)
print(pass.pass?.descriptionField as Any)
}) { (error) in
print(error as Any)
}
PassClient.shared.getPass(passType: "demo.coupon", serialNumber: "#Your pass serial number", onSuccess: { (pass) in
print(pass.urls as Any)
print(pass.passType as Any)
print(pass.serialNumber as Any)
print(pass.pass?.logoText as Any)
print(pass.pass?.descriptionField as Any)
}) { (error) in
print(error as Any)
}
PassClient.shared.getPassTemplate(passType: "demo.coupon", onSuccess: { (passTemplate) in
print(passTemplate.id as Any)
print(passTemplate.passTypeId as Any)
print(passTemplate.name as Any)
}) { (error) in
print(error as Any)
}
PassClient.shared.putPass(pass: PassRequest(passType: "demo.coupon", pass: ["passTitle": "Example passTitleValue", "logoText": "Example logoTextValue", "organizationName": "Example organizationNameValue", "description": "Example descriptionValue"], serialNumber: "#Your pass serial number"), onSuccess: { (pass) in
print(pass.urls as Any)
print(pass.passType as Any)
print(pass.serialNumber as Any)
print(pass.pass?.logoText as Any)
print(pass.pass?.descriptionField as Any)
print(pass.pass?.expiration as Any)
}) { (error) in
print(error as Any)
}
PassClient.shared.deletePass(passType: "demo.coupon", serialNumber: pass?.serialNumber ?? "", clientPassData: [:], onSuccess: {
print("Pass deleted successfully")
}) { (error) in
print(error as Any)
}