![](/img/trans.png)
[英]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.