IONIC 3:在iOS中,onNotification不会在前台触发吗? [英] IONIC 3: onNotification not fire in foreground in IOS?
问题描述
我已经在ionic中实现了推送通知,一切在android上都可以正常运行,但是在IOS中却遇到了不同的情况:
I have implemented push notification in ionic Everything working fine on android and but in IOS got different scenario:
- 前景:不会触发onNotification以及android正常工作.
- 背景:收到推送通知,但是从通知中轻按后没有任何反应
app.component.ts
this.fcm.onNotification().subscribe(data => {
if(data.wasTapped){
console.log(data.wasTapped);
//redirectPageViaNotificationType for redirect page...
this.redirectPageViaNotificationType(data);
} else {
//Notification was received in foreground. Maybe the user needs to be notified
// if application open, show
let confirmAlert = this.alertCtrl.create({
title: (<any>data).title,
message: (<any>data).body,
buttons: [{
text: 'Ignore',
role: 'cancel'
},{
text: 'View',
handler: () => {
//redirectPageViaNotificationType for redirect page...
this.redirectPageViaNotificationType(data);
}
}]
});
confirmAlert.present();
}
});
当收到任何推送通知时,当我的应用程序关闭或后台运行时,它的显示通知均不执行this.fcm.onNotification()函数.我只是调试了这个问题,并在xcode控制台中注意到了这一点:
when any push notification is received its showing notification when my application is closed or background it does not executing the this.fcm.onNotification()function. And i just debug this issue and noticed this, in my xcode console its showing:
尝试过的解决方案
链接:
-
在通知有效负载中添加"content_available":true ,但不适用于我.
https ://forum.cometchat.com/t/ionic-push-notification-not-triggered-when-in-foreground-ios/620/8
删除以下插件:
npm i cordova-plugin-fcm-with-dependecy-updated和local-notification插件,然后再次添加但对我不起作用.
npm i cordova-plugin-fcm-with-dependecy-updated and local-notification plugin and add it again but not worked for me.
任何人都可以告诉我为什么会出现问题以及出了什么问题吗?
can any one please tell me why its happing and what's going wrong?
推荐答案
如果要处理请求,即不仅要像使用content-available: '1'
那样在后台处理某些数据,还必须将其保留为content-available: '0'
If you want to handle the requests, ie not just process some data in the background as you would with content-available: '1'
, you must leave it as content-available: '0'
.
我使用PHP和Kreait/Firebase处理推式通知.然后对于iOS,这是我的配置:
I process Push notifications with PHP and Kreait/Firebase. Then for iOS this is my config:
$notification = Notification::fromArray([
'title' => $title,
'body' => $message,
]);
$data = MessageData::fromArray([
'some_key' => $value,
]);
$apnsConfig = ApnsConfig::fromArray([
'payload' => [
'aps' => [
'badge' => 1,
'content-available' => 0,
'notId' => UUID::v4()
],
],
]);
$cloudMessage = CloudMessage::new()
->withNotification($notification)
->withData($data)
->withApnsConfig($apnsConfig);
$apnsResult = self::$messaging->sendMulticast($cloudMessage, $iosTokens);
您可以在此处找到文档: https://firebase.google.com/docs/云消息.对于Android,我使用curl,但是那时kreaits的fcm实现存在一些问题.他们确实发布了我要检查的新版本,以检查它是否已解决此问题.
You can find the documentation here: https://firebase.google.com/docs/cloud-messaging. For Android I used curl however, there was some problem back then with kreaits' fcm implementation. They did publish a new release that I ment to check whether it fixed this.
希望这会有所帮助.
这篇关于IONIC 3:在iOS中,onNotification不会在前台触发吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!