通知中心问题 [英] Issue with notification hub

查看:69
本文介绍了通知中心问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是天青通知中心的新手.我从文档中尝试过.但无法做到这个名字.在这方面需要一些帮助.

I am new to azure notification hub. I tried from the documentation. But not able to do the name . Need some help on this .

尝试以下链接如何将设备注册到Azure服务器端的通知中心(使用NodeJS sdk)?

不确定参数.

var azure = require('azure-sb');

var notificationHubService = azure.createNotificationHubService('<Hub Name>','<Connection String>');
var payload={
        alert: 'Hello!'
      };

notificationHubService.createRegistrationId(function(error, registrationId, response){

      if(!error){
        console.log(response);
        console.log(registrationId);


        //RegistrationDescription registration = null;
        //registration.RegistrationId = registrationId;
        //registration.DeviceToken = req.body.token;
        notificationHubService.apns.createOrUpdateNativeRegistration(registrationId, req.body.token, req.token.upn, function(error, response){

            if(!error){
              console.log('Inside : createOrUpdateNativeRegistration' + response);

                notificationHubService.apns.send(null, payload, function(error){
                if(!error){
                  // notification sent

                  console.log('Success: Inside the notification send call to Hub.');
                  }
              });

            }
            else{
              console.log('Error in registering the device with Hub' + error);
            }

        });

      }
      else{
        console.log('Error in generating the registration Id' + error);
      }

  });

在创建registrationID时,我必须将其传递给那里.什么是request.body.token和什么是request.token.upn.我需要APNS

While creating registrationID which registration id i have to pass there. What is request.body.token and what is request.token.upn. I need it for apns

推荐答案

在创建registrationId时,您不必传递任何ID. ** createRegistrationId(callback)** 将callback作为创建注册标识符的参数.

While creating registrationId , you dont have to pass any id. **createRegistrationId(callback)** takes callback as a parameter which creates a registration identifier.

根据总体实现:

/**
* Creates a registration identifier.
*
* @param {Function(error, response)} callback      `error` will contain information
*                                                  if an error occurs; otherwise, `response`
*                                                  will contain information related to this operation.
*/
NotificationHubService.prototype.createRegistrationId = function (callback) {
  validateCallback(callback);
  var webResource = WebResource.post(this.hubName + '/registrationids');
  webResource.headers = {
    'content-length': null,
    'content-type': null
  };
  this._executeRequest(webResource, null, null, null, function (err, rsp) {
    var registrationId = null;
    if (!err) {
      var parsedLocationParts = url.parse(rsp.headers.location).pathname.split('/');
      registrationId = parsedLocationParts[parsedLocationParts.length - 1];
    }
    callback(err, registrationId, rsp);
  });
};

完成RegistrationID创建后,您可以调用 createOrUpdateRegistration(registration,optionsopt,callback),这是相同的总体实现:

Once you are done with RegistrationID Creation then you can call createOrUpdateRegistration(registration, optionsopt, callback) and here is the overall implementation for the same:

/**
* Creates or updates a registration.
*
* @param {string}             registration              The registration to update.
* @param {object}             [options]                 The request options or callback function. Additional properties will be passed as headers.
* @param {object}             [options.etag]            The etag.
* @param {Function(error, response)} callback           `error` will contain information
*                                                       if an error occurs; otherwise, `response`
*                                                       will contain information related to this operation.
*/
NotificationHubService.prototype.createOrUpdateRegistration = function (registration, optionsOrCallback, callback) {
  var options;
  azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
  validateCallback(callback);
  if (!registration || !registration.RegistrationId) {
    throw new Error('Invalid registration');
  }
  var webResource = WebResource.put(this.hubName + '/registrations/' + registration.RegistrationId);
  registration = _.clone(registration);
  var registrationType = registration[Constants.ATOM_METADATA_MARKER]['ContentRootElement'];
  delete registration[Constants.ATOM_METADATA_MARKER];
  delete registration.ExpirationTime;
  delete registration.ETag;
  if (!registration.Expiry) {
    delete registration.Expiry;
  }
  registration.BodyTemplate = '<![CDATA[' + registration.BodyTemplate + ']]>';
  var registrationXml = registrationResult.serialize(registrationType, registration);
  this._executeRequest(webResource, registrationXml, registrationResult, null, callback);
};

您可以找到NotificationHubService.js的完整实现

You can find the complete implementation of NotificationHubService.js here.

希望有帮助.

这篇关于通知中心问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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