Search code examples
c#androidwcfgoogle-cloud-messagingpushsharp

how to use InstanceID to send notification from Server Side ? - GCM with .NET server


I use GCM for pushing Notification messages from my server to Android and iOS devices.

Currently i am using PushSharp library which is used this way:

string senderId = "my server id from google console";
string device_regId = "some device id";

//Create our push services broker
var push = new PushBroker();

//Registering the GCM Service and sending an Android Notification
push.RegisterGcmService(new GcmPushChannelSettings(senderId));

push.QueueNotification(new GcmNotification().ForDeviceRegistrationId(device_regId)
                      .WithJson("{\"message\":\"TestMessage!\",\"badge\":1}"));

I have read on google InsanceID Documentation,

The Questions:

1- How to use it on server side?

2- what would change in my current implementation?

3- Is there any example of how to use InsanceID instead of RegisterationId which is used previously and has been deprecated now ?


Solution

  • In short on the server side you can treat InstanceIds the same way you did RegistrationIds, InstanceIds are likely to change more frequently than RegistrationIds but that should not affect your server since RegistrationIds changed as well.

    1- How to use it on server side?

    There should be no change on the server side when using InstanceId instead of RegistrationId.

    2- what would change in my current implementation?

    I'm not a push sharp expert but I don't think anything would need to change here either. The InstanceId is an application instance identifier same as RegistrationId was.

    Is there any example of how to use InsanceId instead of RegisterationId which is used previously and has been deprecated now ?

    Here is an example in java where the to field is set to the InstanceId if one exists. I'm assuming that push sharp is doing something similar under the covers.