Question

I need to get the data from an iOS Passbook file to use in my Windows Phone application. I'm able to get it downloaded but how do I get the data from it? It seems binary?

Was it helpful?

Solution

The .pkpass file is actually a ZIP archive. Inside the archive you'll find a pass.json file which contain all meta data for the pass.

Use the Windows Phone compatible ZIP library Silverlight SharpZipLib to extract pass.json from the .pkpass.

string passDotJsonAsJson = null;
using(Stream pkpassAsStream = await client.GetPkpass())
{
    responseStream.Position = 0;
    using(ZipFile pkpass = new ZipFile(pkpassAsStream))
    {
        var passDotJson = pkpass.GetEntry("pass.json");

        using (var passDotJsonAsStream = pkpass.GetInputStream(passDotJson)) 
        {
            var reader = new StreamReader(passDotJsonAsStream);
            passDotJsonAsJson = await reader.ReadToEndAsync();
        }
    }
}

And there you have it. passDotJsonAsJson does now contain the pass as a json string. You can now use Json.NET to make it a .NET object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top