Skip to content

Commit

Permalink
Fixed error when using To instead of RegistrationId - GCM
Browse files Browse the repository at this point in the history
Fix for NullReferenceException issue -
#629

Additional fix for retrieving oldRegistrationId from the 'To' field if
'RegistrationIds' is empty or null
  • Loading branch information
jdtaylor91 authored and Redth committed May 10, 2016
1 parent 615068f commit a2f907b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion PushSharp.Google/GcmNotification.cs
Expand Up @@ -14,7 +14,10 @@ public static GcmNotification ForSingleResult (GcmResponse response, int resultI
var result = new GcmNotification ();
result.Tag = response.OriginalNotification.Tag;
result.MessageId = response.OriginalNotification.MessageId;
result.RegistrationIds.Add (response.OriginalNotification.RegistrationIds [resultIndex]);

if (response.OriginalNotification.RegistrationIds != null && response.OriginalNotification.RegistrationIds.Count >= (resultIndex + 1))
result.RegistrationIds.Add (response.OriginalNotification.RegistrationIds [resultIndex]);

result.CollapseKey = response.OriginalNotification.CollapseKey;
result.Data = response.OriginalNotification.Data;
result.DelayWhileIdle = response.OriginalNotification.DelayWhileIdle;
Expand Down
16 changes: 14 additions & 2 deletions PushSharp.Google/GcmServiceConnection.cs
Expand Up @@ -119,7 +119,13 @@ async Task processResponseOk (HttpResponseMessage httpResponse, GcmNotification
var oldRegistrationId = string.Empty;

if (singleResultNotification.RegistrationIds != null && singleResultNotification.RegistrationIds.Count > 0)
oldRegistrationId = singleResultNotification.RegistrationIds [0];
{
oldRegistrationId = singleResultNotification.RegistrationIds[0];
}
else if (!string.IsNullOrEmpty(singleResultNotification.To))
{
oldRegistrationId = singleResultNotification.To;
}

multicastResult.Failed.Add (singleResultNotification, new DeviceSubscriptonExpiredException {
OldSubscriptionId = oldRegistrationId,
Expand All @@ -131,7 +137,13 @@ async Task processResponseOk (HttpResponseMessage httpResponse, GcmNotification
var oldRegistrationId = string.Empty;

if (singleResultNotification.RegistrationIds != null && singleResultNotification.RegistrationIds.Count > 0)
oldRegistrationId = singleResultNotification.RegistrationIds [0];
{
oldRegistrationId = singleResultNotification.RegistrationIds[0];
}
else if (!string.IsNullOrEmpty(singleResultNotification.To))
{
oldRegistrationId = singleResultNotification.To;
}

multicastResult.Failed.Add (singleResultNotification, new DeviceSubscriptonExpiredException { OldSubscriptionId = oldRegistrationId });
} else {
Expand Down

0 comments on commit a2f907b

Please sign in to comment.