0

We are implementing an application using Unity 3d and we are consuming the Azure Push Notification REST API. But there are a couple of issues and questions on how to successfully send and receive the message.

For testing we are using Advanced Rest client extension for chrome. We are able to create the registration by using the native template ( check https://msdn.microsoft.com/en-us/library/azure/dn223265.aspx )

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
    <content type="application/xml">
        <GcmRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
            <Tags></Tags>
            <GcmRegistrationId>Some Id from somewhere</GcmRegistrationId> 
        </GcmRegistrationDescription>
    </content>
</entry>

So far we are sending the request with empty Tags, and we are not sure what the GcmRegistration should be, the weird thing is that no matter what we send there we get a valid response.

<entry a:etag="W/"1"">
  <id>https://cloudservicechat-ns.servicebus.windows.net/cloudservicechat/registrations/8760279628548469956-1956153846630646542-1?api-version=2015-01</id>
  <title type="text">8760279628548469956-1956153846630646542-1</title>
  <published>2016-06-01T15:15:16Z</published>
  <updated>2016-06-01T15:15:16Z</updated>
  <link rel="self" href="https://cloudservicechat-ns.servicebus.windows.net/cloudservicechat/registrations/8760279628548469956-1956153846630646542-1?api-version=2015-01" />
  <content type="application/xml">
    <GcmRegistrationDescription>
    <ETag>1</ETag>
    <ExpirationTime>2016-08-30T15:15:16.215Z</ExpirationTime>
    <RegistrationId>8760279628548469956-1956153846630646542-1</RegistrationId>
    <GcmRegistrationId>Some Id from somewhere</GcmRegistrationId>
    </GcmRegistrationDescription>
  </content>
</entry>

Now we are trying to send the notification (https://msdn.microsoft.com/en-us/library/azure/dn223273.aspx) but we are not sure of the correct payload to use from azure when using GCM According to the documentation in GCM the payload would be something like this

  {
    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification" : {
      "body" : "great match!",
      "title" : "Portugal vs. Denmark",
      "icon" : "myicon"
    }
  }

However no matter what we do, we always get an Unauthorized response.

Also tried to use the registration using templates, but we are not sure what we should add in (check https://msdn.microsoft.com/en-us/library/azure/dn223265.aspx)

So the questions would be * Where we can get the GcmRegistrationId from? * How we should replace format the {BodyTemplate} * What would be a valid notification payload to use using Azure Test Send

Thanks for the help

Eduardo Fonseca
  • 435
  • 1
  • 6
  • 19

1 Answers1

0

Based from this documentation, you need to add the parameter gcmRegistrationId in the MyHandler class to override the onRegistered method, which registers your device with the mobile service Notification Hub. Example:

@Override
public void onRegistered(Context context,  final String gcmRegistrationId) {
    super.onRegistered(context, gcmRegistrationId);

    new AsyncTask<Void, Void, Void>() {

        protected Void doInBackground(Void... params) {
            try {
                ToDoActivity.mClient.getPush().register(gcmRegistrationId, null);
                return null;
            }
            catch(Exception e) { 
                // handle error             
            }
            return null;            
        }
    }.execute();
}

You can read in this documentation the steps on how to use templates to send platform-agnostic notifications targeting all your devices across platforms, and to personalize broadcast notification to each device.

The standard way to send push notifications is to send, for each notification that is to be sent, a specific payload to platform notification services (WNS, APNS). For example, to send an alert to APNS, the payload is a Json object of the following form:

{"aps": {"alert" : "Hello!" }}

You can check these related threads:

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59