注册推送时的Azure通知中心400

时间:2017-04-23 09:13:39

标签: cordova azure azure-mobile-services azure-notificationhub

我目前遇到Azure通知问题 - 我已经为生产配置了所有内容,并通过发送测试通知确认了这一点。但是,在应用程序中的第一个'registerForPushNotifications'之后,下次打开它时,我会记录以下错误:

PID[11096] Information Sending response: 400.0 <Error><Code>400</Code><Detail>Installation validation failed with following error(s):&#xD; An invalid tag(s) '_UserId:facebook|10211219930003961,NewVenue' was supplied. Valid tag characters are alphanumeric, _, @, -, ., : and #..TrackingId:9315e728-8777-4cad-a475-956c38dcde36_G6,TimeStamp:4/23/2017 9:09:06 AM</Detail></Error>

我正在使用提供的样板代码注册来自cordova(离子)应用程序的推送。我无法理解我哪里出错了。我想解决这个问题,因为这是目前生产中的一个问题。

订阅代码:

function registerForPushNotifications() {
      pushRegistration = PushNotification.init({
        android: {
          senderID: '<id>'
        },
        ios: {
          alert: 'true',
          badge: 'true',
          sound: 'true'
        },
        wns: {}
      });

      // Handle the registration event.
      pushRegistration.on('registration', function(data) {
        // Get the native platform of the device.
        if (device) {
          debugger
          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') {
            // Register for GCM notifications.
            window.azureClient.push.register('gcm', handle.replace("|",""), {
              mytemplate: {
                body: {
                  data: {
                    message: "{$(messageParam)}"
                  }
                }
              }
            });
          } else if (device.platform === 'iOS') {
            // Register for notifications.
            window.azureClient.push.register('apns', handle.replace("|",""), {
              mytemplate: {
                body: {
                  aps: {
                    alert: "{$(messageParam)}"
                  }
                }
              }
            });
          } else if (device.platform === 'windows') {
            // Register for WNS notifications.
            window.azureClient.push.register('wns', handle.replace("|",""), {
              myTemplate: {
                body: '<toast><visual><binding template="ToastText01"><text id="1">$(messageParam)</text></binding></visual></toast>',
                headers: {
                  'X-WNS-Type': 'wns/toast'
                }
              }
            });
          }
        }
      });

      pushRegistration.on('notification', function(data, d2) {
        alert('Push Received: ' + data.message);
      });

      pushRegistration.on('error', function(err) {
        console.warn("error", err)
      });
    }

1 个答案:

答案 0 :(得分:0)

用于Apache Cordova的Azure移动应用程序SDK不适用于安装。您需要向/push/installations/{applicationId}端点(推送刀片为您配置的端点)执行HTTP POST请求。正文必须是通知中心的有效安装对象。

我使用C#作为我书中的语言(http://aka.ms/zumobook)来讨论这个过程。这将允许您微调您发送的推送参数,因为您发送的是与推送对象直接相关的配置对象。

相关问题