使用标签注册推送通知不起作用 [英] Registering Push Notifications with Tags not working

查看:86
本文介绍了使用标签注册推送通知不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cordele应用程序(使用Telerik Appbuilder)并使用此Azure移动服务插件( https://github.com/Azure/azure-mobile-apps-cordova-client )注册推送通知.我从PNS(gcm和apns)获得了成功的响应,并且使用Notification hub进行注册(注册事件)的调用在下面也返回了成功的响应.当我从Azure通知中心使用测试发送"实用程序发送通知而未指定标签时,在设备上(在IOS和Android上)都收到了通知,但是当我尝试使用标签发送通知时,没有收到通知.如何注册标签?

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' } }
      });
  }
});`

MobileServices.Cordova.js插件中的'register'方法说,我们应该将标签指定为Template对象中的属性-参见下文:

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);
    }
);`

推荐答案

出于安全原因,移动应用程序客户端实际上剥离了所有标签.为了注册标签,您将需要直接从后端添加它们.根据您使用的后端,请遵循 https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-backend-how-to-use-server-sdk/#tags .

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.

这篇关于使用标签注册推送通知不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆