【发布时间】:2016-02-11 18:50:01
【问题描述】:
我正在熟悉向设备发送通知,
我目前正在尝试使用 pubnub 和 Google 云消息向我的设备发送通知:
(function() {
var pubnub = PUBNUB.init({
subscribe_key: 'my-subscribe',
publish_key: 'my-publish',
});
var os = 'android';
var regid = '';
var channel = 'mi-canal';
function sendPush() {
var gwtype = (os === 'ios') ? 'apns' : 'gcm';
console.log('sending push notification...',channel,gwtype);
pubnub.mobile_gw_provision({
device_id: 'APA91bE0rX8mfzY0VttACffUPIagSbd5No0xxxxxxxxxxxxxxxxxEHCVFBbzPqPHKG9phyQ31O4W6aEgMUqWANtWrK-zdMsiONUwAbUW4efso8ScemlXGM8tJq0M12oR0E2Kk9',
channel: channel,
op: 'add',
gw_type: gwtype,
error: function(msg){console.log(msg);},
callback: function() {
var message = PNmessage();
message.pubnub = pubnub;
message.callback = function (msg){ console.log(msg); };
message.error = function (msg){ console.log(msg); };
message.channel = channel;
message.apns = {
alert: 'The room temperature is set too high'
};
message.gcm = {
title: 'PubNub Push Demo',
message: 'The room temperature is set too high'
};
message.publish();
}
});
}
sendPush();
})();
哪些日志:
[1, "Sent", "14471821928645156"]
问题是我没有在设备中收到通知,以及 Android 应用程序(cordova 制作)
var pushNotification = window.plugins.pushNotification;
//pushNotification.unregister(successHandler, errorHandler);
pushNotification.register(
successHandler,
errorHandler,
{
'senderID':'api-project-xxxxxxxx',
'ecb':'onNotificationGCM' // callback function
}
);
pusNotification.subscribe({
channel: 'mi-canal',
message: function(m){
alert('Conslog: '+m);
},
error: function (error) {
// Handle error here
console.log(JSON.stringify(error));
}
});
知道我错过了什么吗?
【问题讨论】:
-
嗨托尼!我看到您正在为您使用
Cordova和AndroidHTML5应用程序。您需要等待 PubNub 网络系统分配和配置设备 GCM,我认为这可能是问题所在。
标签: javascript android cordova google-cloud-messaging pubnub