0

I'm trying to save the PKPass with Firebase so that I'm not generating the pass every time the user wants to add the pass to the waller or send the pass. I'm storing the pass.passURL in my firebase database and then fetching it again when the user wants to do something with the pass. Right now all that is happening is the Wallet is opening but the pass isn't showing up. Is this the best way to store the PKPass

Save Function:

func saveTicketIdToDB(pass: PKPass) {

    guard let uid = Auth.auth().currentUser?.uid else { return }

    guard let postId = post?.postId else { return }

    guard let paymentId = paymentId else { return }

    guard let passUrl = pass.passURL as? URL else { return }
    let passUrlString: String = passUrl.absoluteString

    let values = ["passUrl": passUrlString]

    let db = Firestore.firestore()
    db.collection("payments").document(postId).collection("purchases").document(paymentId).updateData(values) { (error) in

        if let error = error {
            print("There was an error", error.localizedDescription)
            return
        }

        print("Successfully saved pkpass into database.")
    }
}

Opening in wallet:

guard let passUrlData = URL(string: passUrl) else { return }

if #available(iOS 10.0, *) {
   UIApplication.shared.open(passUrlData, options: [:], completionHandler: nil)
} else {
   UIApplication.shared.openURL(passUrlData)
}
user
  • 345
  • 2
  • 8
  • 32

1 Answers1

0

You need to store the entire PKPass bundle as a data blob. Then re-create it using PKPass.init(data: ...) and use the PassKit APIs to see if it's in the Wallet already.

pipacs
  • 1,049
  • 11
  • 25