【发布时间】:2018-01-29 05:27:18
【问题描述】:
我有一些奇怪的问题...我在 Ionic 应用程序中使用推送通知进行消息传递,但它有时会起作用...我的代码是:
public initPushNotification() {
if (!this.platform.is('cordova')) {
console.warn('Cordova is not available - Run in physical device. Push notifications not initialized.');
return;
}
let zone = new NgZone({ enableLongStackTrace: false });
zone.run(() => {
this.Push.hasPermission().then((res: any) => {
if (res.isEnabled) {
const options: PushOptions = {
android: {
senderID: GOOGLE_FCM_ID
}
};
let push_object = this.Push.init(options);
push_object.on('registration').subscribe((data: any) => {
this.APIRequest.post('/messages/register-fcm-token', data).subscribe(response => {
console.log(response)
}, err => {
console.log(err)
})
console.log('push.registration', data);
});
push_object.on('notification').subscribe((data: any) => {
console.log('push.notification', data);
this.events.publish('messages:push', data.message);
});
push_object.on('error').subscribe(error => console.error('Error with Push plugin', error));
} else {
alert('We do not have permission to send push notifications');
}
});
});
}
它位于app.component.ts。
一些行为:
- 在
Cat S60手机上最小化应用时可以正常工作 - 有时在某些廉价的
Huawei上最小化应用程序时有效 - 当应用程序按原样打开时,两台设备上都有一些时间。大多数时候不是。
当我将它发送到 Google 时,我会收到 OK 状态。
【问题讨论】:
标签: android cordova push-notification ionic2 cordova-plugins