Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to add pass error #7

Open
nakajimayoshi opened this issue Aug 29, 2023 · 7 comments
Open

Failed to add pass error #7

nakajimayoshi opened this issue Aug 29, 2023 · 7 comments

Comments

@nakajimayoshi
Copy link

nakajimayoshi commented Aug 29, 2023

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:https:///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.

@alvinbaena
Copy link
Owner

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.

@nakajimayoshi
Copy link
Author

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

@alvinbaena
Copy link
Owner

alvinbaena commented Aug 30, 2023

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.

@nakajimayoshi
Copy link
Author

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

@alvinbaena
Copy link
Owner

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

@nakajimayoshi
Copy link
Author

Same result

@alvinbaena
Copy link
Owner

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",
        },
    },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants