Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth authored Aug 8, 2018
2 parents ceb9daf + 864ede0 commit 189a840
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
3 changes: 2 additions & 1 deletion PushSharp.Apple/ApnsConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion PushSharp.Apple/ApnsFeedbackService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -102,13 +102,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);
Expand All @@ -125,18 +131,18 @@ 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 multicastException) {

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 expiredException) {
Expand All @@ -146,16 +152,16 @@ 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}");
}
} 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}");
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
Expand All @@ -164,7 +170,7 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => {
};

gcmBroker.OnNotificationSucceeded += (notification) => {
Console.WriteLine ("GCM Notification Sent!");
Console.WriteLine ("{provider} Notification Sent!");
};

// Start the broker
Expand All @@ -186,7 +192,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).

Expand Down

0 comments on commit 189a840

Please sign in to comment.