Registering Push Notifications with Tags not working

ε祈祈猫儿з 提交于 2019-12-11 06:56:13

问题


I am working on a Cordova app (using Telerik Appbuilder) and using this Azure Mobile Services plugin (https://github.com/Azure/azure-mobile-apps-cordova-client) to register for Push Notifications. I get a successful response from PNS (gcm and apns), and the call to register (registration event) with Notification hub also returns a successful response below. I also get the notifications on device (both on IOS and Android) when I send the notifications using the 'Test Send' utility from Azure notification hub without specifying tags, but no notifications are received when I try to send notifications using Tags. How can I register tags?

`pushRegistration.on('registration', function (data) {
  var client = new WindowsAzure.MobileServiceClient(
        "http://xxxxxx.azurewebsites.net"
    );
  // Get the native platform of the device.
  var platform = device.platform;
  // Get the handle returned during registration.
  var handle = data.registrationId;

  // Set the device-specific message template.
  if (platform == 'android' || platform == 'Android') {                   
      client.push.register('gcm', handle, {
          mytemplate: { body: { data: { message: "{$(messageParam)}" } },
                     tags: ["mynotificationtag", "anothertag"]}                          
      }).then(function(data){
            alert("success");
        },function(error){
            alert(error);
        });
  } else if (device.platform === 'iOS') {
      // Register for notifications.            
      client.push.register('apns', handle, {
          mytemplate: { body: { aps: { alert: "{$(messageParam)}" } },
                      tags: ["mynotificationtag", "anothertag"]}                           
      }).then(function(data){
            alert("success");
        },function(error){
            alert(error);
        });
  } else if (device.platform === 'windows') {
      // Register for WNS notifications.
      client.push.register('wns', handle, {
          myTemplate: {
              body: '<toast><visual><binding template="ToastText01"><text id="1">$(messageParam)</text></binding></visual></toast>',
              headers: { 'X-WNS-Type': 'wns/toast' } }
      });
  }
});`

The 'register' method in plugin in MobileServices.Cordova.js says we should specify tags as a property in Template object - See below:

    `/// <summary>
/// Register a push channel with the Mobile Apps backend to start receiving notifications.
/// </summary>
/// <param name="platform" type="string">
/// The device platform being used - wns, gcm or apns.
/// </param>
/// <param name="pushChannel" type="string">
/// The push channel identifier or URI.
/// </param>
/// <param name="templates" type="string">
/// An object containing template definitions. **_Template objects should contain body, headers and tags properties._**
/// </param>
/// <param name="secondaryTiles" type="string">
/// An object containing template definitions to be used with secondary tiles when using WNS.
/// </param>
Push.prototype.register = Platform.async(
    function (platform, pushChannel, templates, secondaryTiles, callback) {
        Validate.isString(platform, 'platform');
        Validate.notNullOrEmpty(platform, 'platform');

        // in order to support the older callback style completion, we need to check optional parameters
        if (_.isNull(callback) && (typeof templates === 'function')) {
            callback = templates;
            templates = null;
        }

        if (_.isNull(callback) && (typeof secondaryTiles === 'function')) {
            callback = secondaryTiles;
            secondaryTiles = null;
        }

        var requestContent = {
            installationId: this.installationId,
            pushChannel: pushChannel,
            platform: platform,
            templates: stringifyTemplateBodies(templates),
            secondaryTiles: stringifyTemplateBodies(secondaryTiles)
        };

        executeRequest(this.client, 'PUT', pushChannel, requestContent, this.installationId, callback);
    }
);`

回答1:


The mobile apps client actually strips away all tags for security reasons. In order to register for tags, you will want to add them directly from the backend. Depending on which backend you are using, follow https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-node-backend-how-to-use-server-sdk/#push or https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-backend-how-to-use-server-sdk/#tags.



来源:https://stackoverflow.com/questions/39542761/registering-push-notifications-with-tags-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!