I put together a webservice that generates a pass. When I try to download the pass I get back nil. How do I connect my firebase cloud service and download the pass or just convert the bufferData my server generates and convert that to something that I can pass into the PKPass.init method to generate a pass?
Download function
func downloadPass(completion: @escaping((Bool) -> () )) {
self.storageRef.child("passes/custom.pkpass").getData(maxSize: Int64(1 * 1024 * 1024)) { data, error in
if let error = error {
print("Error downloading resource: " + error.localizedDescription)
}
else {
do {
let canAddPassResult = PKAddPassesViewController.canAddPasses()
if (canAddPassResult) {
print("Can add passes. Proceed with creating pass.")
self.newPass = try PKPass.init(data: data!)
completion(true)
}
else {
print("Can NOT add pass. Abort!")
completion(false)
}
}
catch {
print("Something is wrong.")
completion(false)
}
}
}
}
Upon adding self.newPass
to my Addpassview
, it crashes and I get back that the pass is nil
.
struct AddPassView: UIViewControllerRepresentable {
typealias UIViewControllerType = PKAddPassesViewController
@Environment(\.presentationMode) var presentationMode
@Binding var pass: PKPass?
func makeUIViewController(context: Context) -> PKAddPassesViewController {
let passVC = PKAddPassesViewController(pass: self.pass!)
return passVC!
}
func updateUIViewController(_ uiViewController: PKAddPassesViewController, context: Context) {
// Nothing goes here
}
}