Skip to content

Commit 211c0eb

Browse files
committed
Try and avoid specifying both To and RegistrationIds in GCM
This should help with issue #629
1 parent 5e81a6e commit 211c0eb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

PushSharp.Google/GcmNotification.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,15 @@ public bool IsDeviceRegistrationIdValid ()
141141

142142
internal string GetJson ()
143143
{
144-
return JsonConvert.SerializeObject (this);
144+
// If 'To' was used instead of RegistrationIds, let's make RegistrationId's null
145+
// so we don't serialize an empty array for this property
146+
// otherwise, google will complain that we specified both instead
147+
if (RegistrationIds != null && RegistrationIds.Count <= 0 && !string.IsNullOrEmpty (To))
148+
RegistrationIds = null;
149+
150+
// Ignore null values
151+
return JsonConvert.SerializeObject (this,
152+
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
145153
}
146154

147155
public override string ToString ()

0 commit comments

Comments
 (0)