Mon*_*key 4 cordova cordova-plugins phonegap-pushplugin
我已经设置了推送通知插件并调用了register方法,但它只返回一个字符串"OK"而不是设备ID.我如何获得注册的设备ID?
$window.plugins.pushNotification.register(
function (result) {
q.resolve(result); //this always just returns the string "OK", how do I get the device ID?
},
function (error) {
console.log(error);
q.reject(error);
},
config);
return q.promise;
},
Run Code Online (Sandbox Code Playgroud)
e.regid为null,取自此示例
// Android and Amazon Fire OS
function onNotification(e) {
$("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
console.log("regID = " + e.regid);
}
break;
case 'message':
// if this flag is set, this noti
Run Code Online (Sandbox Code Playgroud)
所以我只是误解了推送库中的回调.iOS上的寄存器函数回调返回一个字符串标记,在Android中它只返回一个成功处理程序.Android版本中的注册事件的令牌ID必须在推送通知ecb处理程序而不是注册回调中处理.
所以在他们的例子中
if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
pushNotification.register(
successHandler,
errorHandler,
{
"senderID":"replace_with_sender_id",
"ecb":"onNotification"
});
}
Run Code Online (Sandbox Code Playgroud)
该函数在config属性"ecb"中设置为"onNotification"而不是在sucess处理程序中.
在这种情况下,您可以在原始问题中使用onNotification示例.我的错误是将onNotification函数作为Android中的成功处理程序传递,但实际情况并非如此.
| 归档时间: |
|
| 查看次数: |
2712 次 |
| 最近记录: |