我必须在用角6和Phonegap编写的应用程序中实现推送通知处理。我安装了phonegap-plugin,当我在index.html中使用它时,它一般都能工作:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
if (device.platform === 'Android') {
setPushNotifications();
} else {
pushID = null;
}
}
function setPushNotifications() {
push = PushNotification.init({
"android": {
"senderID": "xxx",
"icon": "notify_icon",
"iconColor": "#1f5382"
},
"ios": {
"sound": true,
"vibration": true,
"badge": true
},
});
push.on('registration', (data) => {
pushID = data.registrationId;
});
push.on('notification', data => {
alert('PUSH arrived!');
// go to another view in Angular... HOW :(
});
}我收到通知,系统显示它,但现在我必须去看。具有通知id的新闻页。我不能通过window.location实现这一点,当我试图声明var PushNotification: any;在app.component构造函数中,TS告诉我PushNotification没有声明。有小费吗?
发布于 2018-12-13 10:39:39
您需要在platformBrowserDynamic().bootstrapModule(AppModule)中用onDeviceReady包装main.ts:
const onDeviceReady = () => {
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
}
document.addEventListener('deviceready', onDeviceReady, false);否则,AppModule是在科多瓦插件加载之前启动的,这就是为什么你有未定义的PushNotification。
第二件事是
我试图在PushNotification构造函数中声明var app.component : any;
declare let PushNotification: any;应该在AppComponent类之外。
https://stackoverflow.com/questions/51135884
复制相似问题