Sto usando node.js (framework server) e mongoose.js (modellazione di schemi basati su mongo) come back-end per un'app iOS e sto usando Mocha (framwork di test) per assicurarmi che tutto funzioni.Test per notifica push Apple
Quello che voglio veramente sapere, e non posso trovare documentazione su, è come testare sul server se le notifiche push vengono inviate correttamente. Sto usando l'apnagent e al momento riesco a vedere che le notifiche push vengono inviate correttamente controllando manualmente il mio dispositivo, ma ho difficoltà a trovare un modo automatico per verificare che funzionino correttamente.
Questa può essere una descrizione sufficiente per rispondere a un livello elevato di ciò che è necessario fare. Ma nel caso in cui esso non è qui è il codice vero e proprio:
Mongoose modello spara una notifica push al momento della creazione:
#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 devices (%d):", devices.length
console.log devices
for token in devices
sendMessageToDevice doc, token
#send some verification here that the code ran correctly???
Poi nel mio file di test Mocha ho:
it 'should receive push notification from fort creation', (done) ->
#some logic here to verify that push notifications were sent
done()
Grazie mille per una risposta esaustiva e per il collegamento alla cocca, non ne avevo mai sentito parlare in precedenza e sembra un buon modo per testare alcune cose! – clifgray