phpios.netswiftapple-wallet

Apple wallet- Pass not getting updated


I am able to add pass received from server to Apple wallet but not getting why pass not getting updated. So, my queries as an iOS developer are:

  1. Who will create pass if it needs to be updated from backend automatically without my iOS app interaction

  2. What is the role of my iOS app in handling pass(adding updating data in Apple Wallet)

  3. Who will register for push notifications after pass added to wallet and who will get push token

  4. At whose end backend or app end this api will be called

    https://yourpasshost.example.com/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}

Below is my code for adding pass to wallet:

 let passURL = URL(string: "https://firebasestorage.googleapis.com/v0/b/iospasswallet.appspot.com/o/pass1.pkpass?alt=media&token=397cb8-d939-4241-b8f8-a1f7e4f8d937")!

    // Use URLSession to download pass data asynchronously
    let session = URLSession.shared
    let task = session.dataTask(with: passURL) { (data, response, error) in
        if let error = error {
            print("Error downloading pass data: \(error)")
            return
        }
        
        guard let passData = data else {
            print("Failed to get pass data")
            return
        }

        do {
            let pass = try PKPass(data: passData)
            let passLibrary = PKPassLibrary()
            passLibrary.addPasses([pass]) { (status) in
                DispatchQueue.main.async {
                    if status.rawValue == 0 {
                        print("Pass added successfully")
                    } else if status.rawValue == 1 {
                        print("Pass review successfully")
                    } else {
                        print("Cancelled Status: \(status.rawValue)")
                    }
                }
            }
        } catch {
            print("Error creating pass: \(error)")
        }
    }

    task.resume()

Thanks in advance.


Solution

    1. You have to create the pass if you want to be able to update it.
    2. Your app doesn't have much to do - just getting a pass (maybe from sone internal API of yours), and handing it over to the system.
    3. The act of adding a pass automatically registers the device for push notifications, and the registration callback you'll receive will contain a push token to allow you to do that.
    4. In that example, yourpasshost.example.com is most likely the same server that you got the pass from, i.e. yours.

    One key thing to realise is that once a pass is installed, it's independent of how it was installed, and all of your interaction with it from that point occurs via the web service that you have to build according to Apple's spec.