Ich habe AWS-Dokumentation gesucht und einige Stunden vergeudet, konnte aber die API und den Code zum Senden von Push-Benachrichtigungen mit Node JS nicht finden. Kann jemand beim Senden von AWS SNS-Push-Benachrichtigungen mit Node JS auf Android- und iOS-Geräten helfen?AWS SNS-Push-Benachrichtigung mit Node JS
1
A
Antwort
2
Verwenden SNS-mobile
Das folgende Beispiel erzeugt eine SNS-Instanz für eine Android-Anwendung von einem
PlatformApplicationArn identifiziertvar SNS = require('sns-mobile'),
EVENTS = SNS.EVENTS;
var SNS_KEY_ID = process.env['SNS_KEY_ID'],
SNS_ACCESS_KEY = process.env['SNS_ACCESS_KEY'],
ANDROID_ARN = process.env['SNS_ANDROID_ARN'];
var androidApp = new SNS({
platform: SNS.SUPPORTED_PLATFORMS.ANDROID,
region: 'eu-west-1',
apiVersion: '2010-03-31',
accessKeyId: SNS_ACCESS_KEY,
secretAccessKey: SNS_KEY_ID,
platformApplicationArn: ANDROID_ARN,
//sandbox: true (This is required for targetting (iOS) APNS_SANDBOX only)
});
// Add a user, the endpointArn is their unique id
// endpointArn is required to send messages to the device
androidApp.addUser('some_fake_deviceid_that_i_made_up', JSON.stringify({
some: 'extra data'
}), function(err, endpointArn) {
if(err) {
throw err;
}
// Send a simple String or data to the client
androidApp.sendMessage(enpointArn, 'Hi There!', function(err, messageId) {
if(err) {
throw err;
}
console.log('Message sent, ID was: ' + messageId);
});
});
1
die Antwort.
var AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: '{AWS_KEY}',
secretAccessKey: '{AWS_SECRET}',
region: '{SNS_REGION}'
});
var sns = new AWS.SNS();
var payload = {
default: 'Hello World',
APNS: {
aps: {
alert: 'Hello World',
sound: 'default',
badge: 1
}
}
};
// first have to stringify the inner APNS object...
payload.APNS = JSON.stringify(payload.APNS);
// then have to stringify the entire message payload
payload = JSON.stringify(payload);
console.log('sending push');
sns.publish({
Message: payload, // Required
MessageStructure: 'json',
TargetArn: {{TargetArn}} // Required
}, function(err, data) {
if (err) {
console.log(err.stack);
return;
}
console.log('push sent');
console.log(data);
});
});
Verwandte Themen
- 1. AWS S3-Synchronisierung mit JS/Node SDK
- 2. Node JS - Elastic Beanstalk AWS - Schreibzugriff erlauben
- 3. Node JS - Daten von Busboy nach AWS S3 übertragen
- 4. Autorisierung mit Node JS-Anwendung
- 5. facebook node js logout
- 6. Arbeiten mit eckigen js, Node js server und express js
- 7. Node JS + Passport-Login
- 8. Node JS req.body undefined
- 9. node-js twitter json
- 10. Node JS NPM Installationsfehler
- 11. Node JS Minification
- 12. Node JS-Konfiguration
- 13. Node Js process.stdin
- 14. Node JS - MVC - Namenskonventionen
- 15. Node JS App hosting
- 16. node js cpu 100%
- 17. Node JS Return Hostname
- 18. CRUD-Operationen mit DynamoDB mit expressjs (node js)
- 19. Anwendung Callback-Design-Muster mit Node-JS
- 20. Verwenden einer Node JS-Bibliothek mit QML
- 21. Mit Node-Js als Nachrichtenschicht vorbei
- 22. Importieren von Objektdaten mit get Node js
- 23. Wie angular 2 mit oauth node js
- 24. Wie POST-Array zu mongodb mit Angular js & Node js
- 25. ibm bluemix node js files
- 26. Async Node JS Abfrage Verbindung
- 27. node js callback as var
- 28. Erstellen einer Benutzersitzung - NODE js
- 29. Node Js und Ebay api
- 30. node js 's Buffer.toString (' binary ')
http://docs.aws.amazon.com/sns/latest/dg/SNSMobilePushBaiduAPI.html – Adiii
http://stackoverflow.com/questions/21609121/anyone-using-node-js-with- Amazon-SNS-und-Apple-Push-Benachrichtigungen – Adiii