passkit icon indicating copy to clipboard operation
passkit copied to clipboard

Failed to add pass error

Open nakajimayoshi opened this issue 1 year ago • 7 comments

Upon generating the .pkpass from the file template, the iOS Simulator throws the following error instead of loading the pass:

Failed to add pass: 'file:///Users/dev/Documents/projects/pass/pass.pkpass' Error Domain=PKPassKitErrorDomain Code=1 "No data supplied" UserInfo={NSLocalizedDescription=No data supplied}.

I've used the code from the README to generate the .pkpass:

package main

import (
	"archive/zip"
	"bytes"
	"fmt"
	"io/ioutil"
	"os"

	"github.com/alvinbaena/passkit"
	"github.com/google/uuid"
)

func main() {

	c := passkit.NewGenericPass()

	field := passkit.Field{
		Key:   "key",
		Label: "label",
		Value: "value",
	}

	serial := uuid.NewString()

	fmt.Printf("pass id: %s\n", serial)

	c.AddHeaderField(field)
	c.AddPrimaryFields(field)
	c.AddSecondaryFields(field)
	c.AddAuxiliaryFields(field)
	c.AddBackFields(field)

	pass := passkit.Pass{
		FormatVersion:      1,
		TeamIdentifier:     "==TEAM-ID==",
		PassTypeIdentifier: "==Pass-Identifier==",
		OrganizationName:   "orgName",
		SerialNumber:       serial,
		Description:        "test",
		Generic:            c,
		Barcodes: []passkit.Barcode{
			{
				Format:          passkit.BarcodeFormatQR,
				Message:         "1312312312312312312312312312",
				MessageEncoding: "utf-8",
			},
		},
	}

	template := passkit.NewFolderPassTemplate("passes/mypass.pass")

	signInfo, err := passkit.LoadSigningInformationFromFiles("certs/passmaker.p12", "test", "certs/wwdr.cer")

	signer := passkit.NewMemoryBasedSigner()

	if err != nil {
		panic(err)
	}

	fmt.Print("Pass signed\n")

	z, err := signer.CreateSignedAndZippedPassArchive(&pass, template, signInfo)

	if err != nil {
		fmt.Println("Error creating archive:", err)
		return
	}

	fmt.Print("Archive Created\n")

	err = os.WriteFile("pass.pkpass", z, 0644)

	if err != nil {
		panic(err)
	}

	fmt.Print("Finished creating pass\n")
}

No certificate errors are being thrown, so I think it's safe to say it's not related to certificates/signing.

I'm using the the Generic.pass from Apple as a template, and replaced the values of the JSON with the above fields. I also printed the contents of the pass.json after it was loaded into memory and all the fields were filled out as they were supposed to be, but I still get this error.

nakajimayoshi avatar Aug 29 '23 09:08 nakajimayoshi

If you extract the generated pkpass file (it's just a signed zip file) are all the files from the template folder present? are the files named and placed as per the Apple documentation?. This library doesn't actually check that the files in the folder are correctly named.

alvinbaena avatar Aug 29 '23 12:08 alvinbaena

@alvinbaena Don't see the option to unzip the file. Is it possible to unzip without installing 3rd party software?

nakajimayoshi avatar Aug 30 '23 06:08 nakajimayoshi

Sure, you'd have to do it via the terminal with the unzip command. You can check how the command works with a quick search.

alvinbaena avatar Aug 30 '23 13:08 alvinbaena

Here is the result of unzipping the .pkpass archive: Screenshot 2023-08-31 at 12 45 45

nakajimayoshi avatar Aug 31 '23 03:08 nakajimayoshi

That is indeed weird. Does the same behaviour happen if you try to open the pass on a real device?

alvinbaena avatar Aug 31 '23 13:08 alvinbaena

Same result

nakajimayoshi avatar Sep 01 '23 08:09 nakajimayoshi

Sorry for the late response, I've been a bit busy.

Please try following the new example provided by a community member, and see if the error changes or goes away:

c := passkit.NewBoardingPass(passkit.TransitTypeAir)

// Utility functions for adding fields to a pass
c.AddHeaderField(passkit.Field{
    Key: "your_head_key",
    Label: "your_displayable_head_label",
    Value:"value",
})
c.AddPrimaryFields(passkit.Field{
    Key: "your_prim_key",
    Label: "your_displayable_prim_label",
    Value:"value",
})
c.AddSecondaryFields(passkit.Field{
    Key: "your_sec_key",
    Label: "your_displayable_sec_label",
    Value:"value",
})
c.AddAuxiliaryFields(passkit.Field{
    Key: "your_aux_key",
    Label: "your_displayable_aux_label",
    Value:"value",
})
c.AddBackFields(passkit.Field{
    Key: "your_back_key",
    Label: "your_displayable_back_label",
    Value:"value",
})

pass := passkit.Pass{
    FormatVersion:       1,
    TeamIdentifier:      "TEAMID",
    PassTypeIdentifier:  "pass.type.id",
    AuthenticationToken: "123141lkjdasj12314",
    OrganizationName:    "Your Organization",
    SerialNumber:        "1234",
    Description:         "test",
    BoardingPass:         c,
    Barcodes: []passkit.Barcode{
        {
            Format:          passkit.BarcodeFormatPDF417,
            Message:         "1312312312312312312312312312",
            MessageEncoding: "utf-8",
        },
    },
}

alvinbaena avatar Dec 16 '23 04:12 alvinbaena