标签: apnagent

测试Apple推送通知

我使用node.js(服务器框架)和mongoose.js(基于mongo的模式建模)作为iOS应用程序的后端,我使用Mocha(测试框架)来确保一切正常.

我真正想知道的,并且找不到任何文档,是如何在服务器上测试推送通知是否正确发送.我正在使用apnagent,目前我可以看到通过手动检查我的设备正确发送推送通知,但我很难找到一种自动方式来测试它们是否正常工作.


这可能足以说明在高层次上回答需要做什么.但如果不是这里是实际的代码:

Mongoose Model在创建时触发推送通知:

#this code is called after this model is saved in mongodb
eventModel.post 'save', (doc) ->
  #push the message
  sendMessageToDevice = (event, token) ->
    message =
      event_body:
        eventId: event._id
        lat: event.lngLat[1]
        lng: event.lngLat[0]
    agent.createMessage()
      .device(token)
      .alert('New Event! ' + event.description)
      .set(message)
      .send()

  #cycle through the users to push to
  #get all the unique device tokens in the database for APN
  users.getAllUniqueDeviceTokens (error, devices) ->
    if error then return util.handleError error
    console.log "Sending push notices to all …
Run Code Online (Sandbox Code Playgroud)

mongoose apple-push-notifications node.js coffeescript apnagent

5
推荐指数
1
解决办法
1194
查看次数