tomasmcguinness / dotnet-passbook

A .Net Library for generating Apple Passbook (Wallet) files for iOS. Please get involved by creating pull requests and opening issues!
MIT License
316 stars 116 forks source link

apple push notifications stopped working #150

Closed dolphinsd closed 2 years ago

dolphinsd commented 2 years ago

Looks like apple finally took down binary api. From https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/BinaryProviderAPI.html "All developers should migrate their remote notification provider servers to the more capable and more efficient HTTP/2-based API described in Communicating with APNs"

See https://github.com/tomasmcguinness/dotnet-passbook/blob/56a149e955b4f8acb26b8c69f9e7058ddb047b09/Passbook.Sample.Web/Services/SendEmptyPushNotification.cs

Even after getting new certificates from apple, we can connect to applet server but no pass is updated.

I saw your note on https://github.com/tomasmcguinness/dotnet-passbook/issues/149 but we also found this:

https://stackoverflow.com/questions/67308054/sendemptypushnotification-to-gateway-push-apple-com-no-longer-working See section for net core.

Looks like there is a library which can be integrated to do so.

dolphinsd commented 2 years ago

Anyone is looking for solution here it is using dotAPNS library

using dotAPNS; using System.Security.Cryptography.X509Certificates;

//https://github.com/alexalok/dotAPNS Console.WriteLine("Hello, APNS!");

var fileInfo = File.ReadAllBytes("../../../pass.pfx"); var cert = new X509Certificate2(fileInfo, "password"); var apns = ApnsClient.CreateUsingCert(cert); var push = new ApplePush(ApplePushType.Alert) .AddAlert("", "") .AddToken("1f9bd950b35573a032372893728392893d7ed858291c9f8fdc967b88250e621b62");

try { var response = await apns.SendAsync(push); if (response.IsSuccessful) { Console.WriteLine("An alert push has been successfully sent!"); } else { switch (response.Reason) { case ApnsResponseReason.BadCertificateEnvironment: // The client certificate is for the wrong environment. // TODO: retry on another environment break; // TODO: process other reasons we might be interested in default: throw new ArgumentOutOfRangeException(nameof(response.Reason), response.Reason, null); } Console.WriteLine("Failed to send a push, APNs reported an error: " + response.ReasonString); } } catch (TaskCanceledException) { Console.WriteLine("Failed to send a push: HTTP request timed out."); } catch (HttpRequestException ex) { Console.WriteLine("Failed to send a push. HTTP request failed: " + ex); } catch (ApnsCertificateExpiredException) { Console.WriteLine("APNs certificate has expired. No more push notifications can be sent using it until it is replaced with a new one."); }

ruhonir-van-altair commented 1 year ago

Anyone is looking for solution here it is using dotAPNS library

using dotAPNS; using System.Security.Cryptography.X509Certificates;

//https://github.com/alexalok/dotAPNS Console.WriteLine("Hello, APNS!");

var fileInfo = File.ReadAllBytes("../../../pass.pfx"); var cert = new X509Certificate2(fileInfo, "password"); var apns = ApnsClient.CreateUsingCert(cert); var push = new ApplePush(ApplePushType.Alert) .AddAlert("", "") .AddToken("1f9bd950b35573a032372893728392893d7ed858291c9f8fdc967b88250e621b62");

try { var response = await apns.SendAsync(push); if (response.IsSuccessful) { Console.WriteLine("An alert push has been successfully sent!"); } else { switch (response.Reason) { case ApnsResponseReason.BadCertificateEnvironment: // The client certificate is for the wrong environment. // TODO: retry on another environment break; // TODO: process other reasons we might be interested in default: throw new ArgumentOutOfRangeException(nameof(response.Reason), response.Reason, null); } Console.WriteLine("Failed to send a push, APNs reported an error: " + response.ReasonString); } } catch (TaskCanceledException) { Console.WriteLine("Failed to send a push: HTTP request timed out."); } catch (HttpRequestException ex) { Console.WriteLine("Failed to send a push. HTTP request failed: " + ex); } catch (ApnsCertificateExpiredException) { Console.WriteLine("APNs certificate has expired. No more push notifications can be sent using it until it is replaced with a new one."); }

Hello @dolphinsd, did you have any problems with your certificate? I get exception using your code: No credentials are available in the security package

Have you encountered this error?