Skip to content

Commit

Permalink
Merge pull request #21 from schjonhaug/support-3x-images
Browse files Browse the repository at this point in the history
Add support for 3x images
  • Loading branch information
justdmitry authored Apr 24, 2023
2 parents 0e59052 + c6d27e5 commit c4a71a9
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 4 deletions.
2 changes: 2 additions & 0 deletions PassKitHelper.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ public static async Task GenerateSamplePass(IPassKitHelper passKitHelper)
var package = await passKitHelper.CreateNewPassPackage(pass)
.Icon(await File.ReadAllBytesAsync("images/icon.png"))
.Icon2X(await File.ReadAllBytesAsync("images/[email protected]"))
.Icon3X(await File.ReadAllBytesAsync("images/[email protected]"))
.Logo(await File.ReadAllBytesAsync("images/logo.jpg"))
.Strip(await File.ReadAllBytesAsync("images/strip.jpg"))
.Strip2X(await File.ReadAllBytesAsync("images/[email protected]"))
.Strip3X(await File.ReadAllBytesAsync("images/[email protected]"))
.SignAndBuildAsync();

await File.WriteAllBytesAsync("Sample.pkpass", package.ToArray());
Expand Down
113 changes: 113 additions & 0 deletions PassKitHelper/Extensions/PassPackageBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ public static PassPackageBuilder Background2X(this PassPackageBuilder builder, S
return builder;
}

/// <summary>
/// 3X-version of Background.
/// </summary>
public static PassPackageBuilder Background3X(this PassPackageBuilder builder, byte[] content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// 3X-version of Background.
/// </summary>
public static PassPackageBuilder Background3X(this PassPackageBuilder builder, Stream content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// The image displayed on the front of the pass near the barcode.
/// </summary>
Expand Down Expand Up @@ -87,6 +105,24 @@ public static PassPackageBuilder Footer2X(this PassPackageBuilder builder, Strea
return builder;
}

/// <summary>
/// 3X-version of Footer.
/// </summary>
public static PassPackageBuilder Footer3X(this PassPackageBuilder builder, byte[] content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// 3X-version of Footer.
/// </summary>
public static PassPackageBuilder Footer3X(this PassPackageBuilder builder, Stream content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// The pass’s icon. This is displayed in notifications and in emails that have a pass attached, and on the lock screen.
/// </summary>
Expand Down Expand Up @@ -129,6 +165,24 @@ public static PassPackageBuilder Icon2X(this PassPackageBuilder builder, Stream
return builder;
}

/// <summary>
/// 3X-version of Icon.
/// </summary>
public static PassPackageBuilder Icon3X(this PassPackageBuilder builder, byte[] content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// 3X-version of Icon.
/// </summary>
public static PassPackageBuilder Icon3X(this PassPackageBuilder builder, Stream content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// The image displayed on the front of the pass in the top left.
/// </summary>
Expand Down Expand Up @@ -165,6 +219,24 @@ public static PassPackageBuilder Logo2X(this PassPackageBuilder builder, Stream
return builder;
}

/// <summary>
/// 3X-version of Logo.
/// </summary>
public static PassPackageBuilder Logo3X(this PassPackageBuilder builder, byte[] content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// 3X-version of Logo.
/// </summary>
public static PassPackageBuilder Logo3X(this PassPackageBuilder builder, Stream content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// The image displayed behind the primary fields on the front of the pass.
/// </summary>
Expand Down Expand Up @@ -201,6 +273,24 @@ public static PassPackageBuilder Strip2X(this PassPackageBuilder builder, Stream
return builder;
}

/// <summary>
/// 3X-version of Strip.
/// </summary>
public static PassPackageBuilder Strip3X(this PassPackageBuilder builder, byte[] content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// 3X-version of Strip.
/// </summary>
public static PassPackageBuilder Strip3X(this PassPackageBuilder builder, Stream content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// An additional image displayed on the front of the pass. For example, on a membership card, the thumbnail could be used to a picture of the cardholder.
/// </summary>
Expand Down Expand Up @@ -237,6 +327,24 @@ public static PassPackageBuilder Thumbnail2X(this PassPackageBuilder builder, St
return builder;
}

/// <summary>
/// 3X-version of Thumbnail.
/// </summary>
public static PassPackageBuilder Thumbnail3X(this PassPackageBuilder builder, byte[] content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

/// <summary>
/// 3X-version of Thumbnail.
/// </summary>
public static PassPackageBuilder Thumbnail3X(this PassPackageBuilder builder, Stream content)
{
builder.AddFile(GetFileName(GetCaller()), content);
return builder;
}

private static string GetCaller([CallerMemberName] string caller = "unknown")
{
return caller;
Expand All @@ -249,6 +357,11 @@ private static string GetFileName(string name)
return name.Replace("2X", "@2X").ToLowerInvariant() + ".png";
}

if (name.EndsWith("3X"))
{
return name.Replace("3X", "@3X").ToLowerInvariant() + ".png";
}

return name.ToLowerInvariant() + ".png";
}
}
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Helper library for all your Apple PassKit (Apple Wallet, Apple Passbook) needs:

**Attention:** Apple Developer Account required!

[![NuGet](https://img.shields.io/nuget/v/PassKitHelper.svg?maxAge=86400&style=flat)](https://www.nuget.org/packages/PassKitHelper/)
[![NuGet](https://img.shields.io/nuget/v/PassKitHelper.svg?maxAge=86400&style=flat)](https://www.nuget.org/packages/PassKitHelper/)

## Features

Expand Down Expand Up @@ -88,9 +88,11 @@ var pass = passKitHelper.CreateNewPass()
var passPackage = passKitHelper.CreateNewPassPackage(pass)
.Icon(await File.ReadAllBytesAsync("images/icon.png"))
.Icon2X(await File.ReadAllBytesAsync("images/[email protected]"))
.Icon3X(await File.ReadAllBytesAsync("images/[email protected]"))
.Logo(await File.ReadAllBytesAsync("images/logo.jpg"))
.Strip(await File.ReadAllBytesAsync("images/strip.jpg"))
.Strip2X(await File.ReadAllBytesAsync("images/[email protected]"));
.Strip2X(await File.ReadAllBytesAsync("images/[email protected]"))
.Strip3X(await File.ReadAllBytesAsync("images/[email protected]"));

MemoryStream packageFile = await passPackage.SignAndBuildAsync();

Expand Down Expand Up @@ -168,19 +170,20 @@ WebServiceURL is hostname of your server and path that equal to one in `UsePassK

When users install your pass packge to their iOS and Mac devices - Apple server call your `RegisterDeviceAsync`. Save `pushToken` value in database, and when you need to update pass on user device - call `IPassKitHelper.SendPushNotificationAsync(pushToken)`.


## Installation

Use NuGet package [PassKitHelper](https://www.nuget.org/packages/PassKitHelper/)
## Dependencies

For `netcoreapp3.1`:

* Microsoft.Extensions.Http, v3.1.1
* Newtonsoft.Json, v12.0.2
* System.Security.Cryptography.Pkcs, v4.6.0

For `netstandard2.0`:

* Microsoft.AspNetCore.Http.Abstractions, v2.1.1
* Microsoft.Extensions.DependencyInjection.Abstractions, v2.1.1
* Microsoft.Extensions.Logging.Abstractions, v2.1.1
Expand All @@ -197,4 +200,4 @@ Tests can be run with `dotnet test`.
## Credits

* Thanks for inspiration to Tomas McGuinness and his [dotnet-passbook](https://github.com/tomasmcguinness/dotnet-passbook) package.
* Thanks to [maxpixel.net](https://www.maxpixel.net) for sample kitten images.
* Thanks to [maxpixel.net](https://www.maxpixel.net) for sample kitten images.

0 comments on commit c4a71a9

Please sign in to comment.