Swift PKPass eror 'The pass cannot be read because it isn’t valid'

爷,独闯天下 提交于 2020-05-17 07:04:38

问题


I'm creating a Ticket from my server and passing it into my ios app but I keep getting this error when I try to pass the JSON data into the PKPass model.

Error Domain=PKPassKitErrorDomain Code=1 "The pass cannot be read because it isn’t valid.

In my server it says that the ticket was created successfully and but I still get this error in Xcode. Am I decoding the data wrong? How can I create the PKPass using the JSON Response?

Server Side code:

exports.createTicket = functions.https.onRequest(async (req, res) => {

const passName = "Event"

try {
  const examplePass = await createPass({
      model: "./models/Event",
      certificates: {
          wwdr: "./models/certs/wwdrc.pem",
          signerCert: "./models/certs/signerCert.pem",
          signerKey: {
              keyFile: "./models/certs/signerKey.pem",
              passphrase: "54321"
          }
      },
      overrides: {
          // keys to be added or overridden
          serialNumber: "AAGH44625236dddaffbda"
      }
  });

  examplePass.barcode("36478105430"); // Random value

// Generate the stream, which gets returned through a Promise
const stream = examplePass.generate();

res.set({
  "Content-Type": "application/vnd.apple.pkpass",
  "Content-disposition": `attachment; filename=${passName}.pkpass`
});

stream.pipe(res);

console.log("Successfully created ticket", stream)
} catch (err) {
console.log("There was an error", err)

    res.set({
        "Content-type": "text/html",
    });

    res.send(err.message);
 }
 });

IOS Side:

AF.request(URLString, method: .post, parameters: requestData).responseString { response in

        guard let data = response.data as? Data else { return }

        do {
            let pass = try PKPass(data: data)
            print(pass)
        } catch {
            print("Error", error)
        }


    }

pass.json

{
"formatVersion": 1,
"passTypeIdentifier": "pass.com.CodyHost.Finder-Dev",
"teamIdentifier": "L9C6U8UKPB",
"organizationName": "Finder",
"description": "Rolling loud new york 2020",
"eventTicket": {}
}

Signature:

MMKABgkqwoZIwobDtw0BBwLCoMKAMMKAAgEBMQswCQYFKw4DAhoFADDCgAYJKsKGSMKGw7cNAQcBAADCoMKCCkkwwoIEIzDCggMLwqADAgECAgEZMA0GCSrChkjChsO3DQEBBQUAMGIxCzAJBgNVBAYTAlVTMRMwEQYDVQQKEwpBcHBsZSBJbmMuMSYwJAYD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xTChMONw6QFwpPCh8OmwozCvzHCggIqMMKCAiYCAQEwwoHCozDCgcKWMQswCQYDVQQGEwJVUzETMBEGA1UECgwKQXBwbGUgSW5jLjEsMCoGA1UECwwjQXBwbGUgV29ybGR3aWRlIERldmVsb3BlciBSZWxhdGlvbnMxRDBCBgNVBAMMO0FwcGxlIFdvcmxkd2lkZSBEZXZlbG9wZXIgUmVsYXRpb25zIENlcnRpZmljYXRpb24gQXV0aG9yaXR5Agh0EMKbw6XChH87woQwCQYFKw4DAhoFAMKgXTAYBgkqwoZIwobDtw0BCQMxCwYJKsKGSMKGw7cNAQcBMBwGCSrChkjChsO3DQEJBTEPFw0xNTA3MjMxODM0NDJaMCMGCSrChkjChsO3DQEJBDEWBBTCs8KcfcKfCsKtw4BOWMOEw6InwpvDt8O0HMOFNEENMA0GCSrChkjChsO3DQEBAQUABMKCAQBRKx/DtsO1RBvDocKKNMOgX8Oow7Uzb0XDsEjDlH3DhMOjdVnDpUVCXngww4BTwqshI8O6SsKIwrbDpcOQwpHChT3Dt8KKwrnDpx9tP1HCgMKMwq52EkxEwpbDgXbDgcOsAkQHS0VLw5gCw4lOwqIpw5ZxYsO4PMONw5kKwrXDpXjCtsKBw70qWS8GbMKdMsK4FsKNwrlVw6JUw7Jiw67DnMKCwqrCtMKRB8KjDwcIbXfCjl89CwbDqcKnwqfCrEkyccKGw7RGTGHCm8OxwpB2UMOYN8OmwqA4w5YQwrwLOWx1w5zDqGfDm8OOw5ULw5fCmhrDggDDiCHCknjDhDQOKSgBwogdV0PDosO6BcOiOinCpTxwwpc6wrfCt8ORIcOfCXzDkFVcWV1cRW7CoDvDmBDDusKvw7DClRlmw7RSTsKHwp3ChifDhMK6wpBBb8KgdsKSw6AWwoBmSwwsw65vwq7Cv8KXdBxKw6Yhw74mEcOAHMOEw5QDAAAAAAAA


回答1:


Looking at your signature and you pass.json, your pass is failing to load because the certificate that has been used to create the signature is:

  • PassTypeId: pass.com.apple.devpubs.example
  • TeamName: A93A5CM278

This doesn't match the passTypeIdentifier and teamName you have in your pass.json.

Replace ./models/certs/signerCert.pem and ./models/certs/signerKey.pem with the correct certificate and key for your PassTypeId Certificate and you should get past this error.

Any pass compiled with the pass.json above still will not load, but for a different reason. The eventTicket object cannot be empty.



来源:https://stackoverflow.com/questions/61479545/swift-pkpass-eror-the-pass-cannot-be-read-because-it-isn-t-valid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!