From 0aa0c3328f8e9b6ef293908e51a148cd003d43c9 Mon Sep 17 00:00:00 2001 From: Filip Andre Larsen Tomren Date: Mon, 3 Jul 2017 12:14:29 +0200 Subject: [PATCH 1/4] Update README.md Based on https://github.com/Redth/PushSharp/issues/752 --- README.md | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b3ae1f9b..5a68ed1c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ PushSharp v4.0 ============== -PushSharp is a server-side library for sending Push Notifications to iOS/OSX (APNS), Android/Chrome (GCM), Windows/Windows Phone, Amazon (ADM) and Blackberry devices! +PushSharp is a server-side library for sending Push Notifications to iOS/OSX (APNS), Android/Chrome (GCM/FCM), Windows/Windows Phone, Amazon (ADM) and Blackberry devices! PushSharp v3.0+ is a complete rewrite of the original library, aimed at taking advantage of things like async/await, HttpClient, and generally a better infrastructure using lessons learned from the old code. @@ -103,13 +103,19 @@ fbs.Check (); ``` -### GCM Sample Usage +### GCM/FCM Sample Usage -Here is how you would send a GCM Notification: +Here is how you would send a GCM/FCM Notification: ```csharp -// Configuration +// Configuration GCM (use this section for GCM) var config = new GcmConfiguration ("GCM-SENDER-ID", "AUTH-TOKEN", null); +var provider = "GCM"; + +// Configuration FCM (use this section for FCM) +// var config = new GcmConfiguration("APIKEY"); +// config.GcmUrl = "https://fcm.googleapis.com/fcm/send"; +// var provider = "FCM"; // Create a new broker var gcmBroker = new GcmServiceBroker (config); @@ -127,19 +133,19 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => { var gcmNotification = notificationException.Notification; var description = notificationException.Description; - Console.WriteLine ($"GCM Notification Failed: ID={gcmNotification.MessageId}, Desc={description}"); + Console.WriteLine ($"{provider} Notification Failed: ID={gcmNotification.MessageId}, Desc={description}"); } else if (ex is GcmMulticastResultException) { var multicastException = (GcmMulticastResultException)ex; foreach (var succeededNotification in multicastException.Succeeded) { - Console.WriteLine ($"GCM Notification Succeeded: ID={succeededNotification.MessageId}"); + Console.WriteLine ($"{provider} Notification Succeeded: ID={succeededNotification.MessageId}"); } foreach (var failedKvp in multicastException.Failed) { var n = failedKvp.Key; var e = failedKvp.Value; - Console.WriteLine ($"GCM Notification Failed: ID={n.MessageId}, Desc={e.Description}"); + Console.WriteLine ($"{provider} Notification Failed: ID={n.MessageId}, Desc={e.Description}"); } } else if (ex is DeviceSubscriptionExpiredException) { @@ -157,9 +163,9 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => { } else if (ex is RetryAfterException) { var retryException = (RetryAfterException)ex; // If you get rate limited, you should stop sending messages until after the RetryAfterUtc date - Console.WriteLine ($"GCM Rate Limited, don't send more until after {retryException.RetryAfterUtc}"); + Console.WriteLine ($"{provider} Rate Limited, don't send more until after {retryException.RetryAfterUtc}"); } else { - Console.WriteLine ("GCM Notification Failed for some unknown reason"); + Console.WriteLine ("{provider} Notification Failed for some unknown reason"); } // Mark it as handled @@ -168,7 +174,7 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => { }; gcmBroker.OnNotificationSucceeded += (notification) => { - Console.WriteLine ("GCM Notification Sent!"); + Console.WriteLine ("{provider} Notification Sent!"); }; // Start the broker @@ -190,7 +196,7 @@ foreach (var regId in MY_REGISTRATION_IDS) { gcmBroker.Stop (); ``` -#### Components of a GCM Notification +#### Components of a GCM/FCM Notification GCM notifications are much more customizable than Apple Push Notifications. More information about the messaging concepts and options can be found [here](https://developers.google.com/cloud-messaging/concept-options#components-of-a-message). From ceb9daf3e7cc8c76bf05aa28740c4c5e924f99ea Mon Sep 17 00:00:00 2001 From: Paito Anderson Date: Thu, 10 Aug 2017 14:20:49 -0400 Subject: [PATCH 2/4] :lipstick: Readme Example Code --- README.md | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b3ae1f9b..df0053d5 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,7 @@ apnsBroker.OnNotificationFailed += (notification, aggregateEx) => { aggregateEx.Handle (ex => { // See what kind of exception it was to further diagnose - if (ex is ApnsNotificationException) { - var notificationException = (ApnsNotificationException)ex; + if (ex is ApnsNotificationException notificationException) { // Deal with the failed notification var apnsNotification = notificationException.Notification; @@ -120,16 +119,14 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => { aggregateEx.Handle (ex => { // See what kind of exception it was to further diagnose - if (ex is GcmNotificationException) { - var notificationException = (GcmNotificationException)ex; + if (ex is GcmNotificationException notificationException) { // Deal with the failed notification var gcmNotification = notificationException.Notification; var description = notificationException.Description; Console.WriteLine ($"GCM Notification Failed: ID={gcmNotification.MessageId}, Desc={description}"); - } else if (ex is GcmMulticastResultException) { - var multicastException = (GcmMulticastResultException)ex; + } else if (ex is GcmMulticastResultException multicastException) { foreach (var succeededNotification in multicastException.Succeeded) { Console.WriteLine ($"GCM Notification Succeeded: ID={succeededNotification.MessageId}"); @@ -142,8 +139,7 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => { Console.WriteLine ($"GCM Notification Failed: ID={n.MessageId}, Desc={e.Description}"); } - } else if (ex is DeviceSubscriptionExpiredException) { - var expiredException = (DeviceSubscriptionExpiredException)ex; + } else if (ex is DeviceSubscriptionExpiredException expiredException) { var oldId = expiredException.OldSubscriptionId; var newId = expiredException.NewSubscriptionId; @@ -154,8 +150,8 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => { // If this value isn't null, our subscription changed and we should update our database Console.WriteLine ($"Device RegistrationId Changed To: {newId}"); } - } else if (ex is RetryAfterException) { - var retryException = (RetryAfterException)ex; + } else if (ex is RetryAfterException retryException) { + // If you get rate limited, you should stop sending messages until after the RetryAfterUtc date Console.WriteLine ($"GCM Rate Limited, don't send more until after {retryException.RetryAfterUtc}"); } else { @@ -212,8 +208,7 @@ wnsBroker.OnNotificationFailed += (notification, aggregateEx) => { aggregateEx.Handle (ex => { // See what kind of exception it was to further diagnose - if (ex is WnsNotificationException) { - var notificationException = (WnsNotificationException)ex; + if (ex is WnsNotificationException notificationException) { Console.WriteLine ($"WNS Notification Failed: {notificationException.Message}"); } else { Console.WriteLine ("WNS Notification Failed for some (Unknown Reason)"); From 98635f096f55a689bac2e187c2996fc2b4d32404 Mon Sep 17 00:00:00 2001 From: Paito Anderson Date: Tue, 22 Aug 2017 12:09:01 -0400 Subject: [PATCH 3/4] Typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b3ae1f9b..8d8f06c2 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => { Console.WriteLine ($"Device RegistrationId Expired: {oldId}"); - if (!string.IsNullOrWhitespace (newId)) { + if (!string.IsNullOrWhiteSpace (newId)) { // If this value isn't null, our subscription changed and we should update our database Console.WriteLine ($"Device RegistrationId Changed To: {newId}"); } From ece23ee6efde57d6654b1e0b87418fae1f0d45c3 Mon Sep 17 00:00:00 2001 From: "CLINITEC\\NSoni" Date: Tue, 23 Jan 2018 18:21:54 -0600 Subject: [PATCH 4/4] Added support for higher TLS versions --- PushSharp.Apple/ApnsConnection.cs | 3 ++- PushSharp.Apple/ApnsFeedbackService.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/PushSharp.Apple/ApnsConnection.cs b/PushSharp.Apple/ApnsConnection.cs index 0908b166..371151b3 100644 --- a/PushSharp.Apple/ApnsConnection.cs +++ b/PushSharp.Apple/ApnsConnection.cs @@ -354,7 +354,8 @@ async Task connect () (sender, targetHost, localCerts, remoteCert, acceptableIssuers) => certificate); try { - stream.AuthenticateAsClient (Configuration.Host, certificates, System.Security.Authentication.SslProtocols.Tls, false); + var tls = System.Security.Authentication.SslProtocols.Tls | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls12; + stream.AuthenticateAsClient(Configuration.Host, certificates, tls, false); } catch (System.Security.Authentication.AuthenticationException ex) { throw new ApnsConnectionException ("SSL Stream Failed to Authenticate as Client", ex); } diff --git a/PushSharp.Apple/ApnsFeedbackService.cs b/PushSharp.Apple/ApnsFeedbackService.cs index 57fb887a..1d078318 100644 --- a/PushSharp.Apple/ApnsFeedbackService.cs +++ b/PushSharp.Apple/ApnsFeedbackService.cs @@ -38,7 +38,8 @@ public void Check () (sender, cert, chain, sslErrs) => { return true; }, (sender, targetHost, localCerts, remoteCert, acceptableIssuers) => { return certificate; }); - stream.AuthenticateAsClient(Configuration.FeedbackHost, certificates, System.Security.Authentication.SslProtocols.Tls, false); + var tls = System.Security.Authentication.SslProtocols.Tls | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls12; + stream.AuthenticateAsClient(Configuration.FeedbackHost, certificates, tls, false); //Set up