[英]How to use push notifications in cordova app?
I have some strange problem... I'm using push notifications for messaging in my Ionic app but it works from time to time... My code is: 我有一个奇怪的问题...我在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');
}
});
});
}
It is located in app.component.ts
. 它位于app.component.ts
。
Some of behavior: 一些行为:
Cat S60
phone 在Cat S60
手机上最小化应用程序时可以正常工作 Huawei
在某些廉价的Huawei
手机上最小化应用程序有时会起作用 When I send it to Google I receive back OK
status. 当我将其发送给Google时,我会返回OK
状态。
You can use one signal for notifications. 您可以使用一个信号进行通知。 It's fast and effective. 快速有效。 You can get detailed information from the links below. 您可以从下面的链接中获取详细信息。
https://documentation.onesignal.com/v3.0/docs/cordova-sdk-setup https://documentation.onesignal.com/v3.0/docs/cordova-sdk-setup
https://www.npmjs.com/package/onesignal-cordova-plug https://www.npmjs.com/package/onesignal-cordova-plug
http://www.plugreg.com/plugin/one-signal/onesignal-cordova-sdk http://www.plugreg.com/plugin/one-signal/onesignal-cordova-sdk
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.