[英]Cordova app that doesn't use push notifications: “Missing push notification entitlement”
[英]How to use push notifications in cordova app?
我有一个奇怪的问题...我在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
状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.