使用标签无效注册推送通知

时间:2016-09-17 04:08:59

标签: cordova push-notification cordova-plugins azure-notificationhub telerik-appbuilder

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

`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'方法说我们应该在Label对象中指定标签作为属性 - 见下文:

    `/// <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 个答案:

答案 0 :(得分:0)

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