【发布时间】:2015-09-02 04:54:10
【问题描述】:
我正在构建一个向 IOS 和 android 手机发送推送通知的应用程序,在搜索时我发现“推送通知”它允许跨平台推送通知我的问题是我们如何为用户设备获取 iosToken 和 androidToken ?如果有人在此之前使用过它,我将不胜感激朝着正确的方向前进。在此先感谢您,您可以在下面找到我的代码。
var PushNotification = require('push-notification');
var DeviceType = PushNotification.DeviceType;
var path = require('path');
// APN: cert.pem, key.pem should be configured
// GCM: configure console to generate gcm.sender
PushNotification.init({
apn: {
cert: path.resolve('./keys/cert.pem'),
key: path.resolve('./keys/key.pem')
},
gcm: {
apiKey: 'gcm-api-key'
}
});
var iosToken = 'iphone-device-token';
var androidToken = 'android-device-token';
var message = 'some text to push...';
var badge = null;
var sound = null;
var payload = null;
// send a notification to a single device
PushNotification.pushSingle(DeviceType.IOS, iosToken, message, badge, sound, payload);
PushNotification.pushSingle(DeviceType.ANDROID, androidToken, message, badge, sound, payload);
【问题讨论】:
-
设备令牌只能由设备生成。所以你必须制作一个 api 来从设备中获取设备令牌。
-
尝试跨平台阅读本教程,但如果您深入其中,则所有链接都指向 gsm 和 apns 案例devgirl.org/2012/10/25/…
标签: android ios node.js push-notification