0

我正在使用Telerik Appbuilder的Cordova應用程序並使用此Azure移動服務插件(https://github.com/Azure/azure-mobile-apps-cordova-client)註冊推送通知。我從PNS(gcm和apns)獲得了成功的響應,並且通知中心註冊(註冊事件)的調用也返回下面的成功響應。當我使用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插件的「註冊」的方法說我們應該在模板對象屬性指定標籤 - 見下文:

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

回答