IONIC 3:onNotification 不会在 IOS 的前台触发? [英] 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 和本地通知插件并再次添加它,但对我不起作用.
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:onNotification 不会在 IOS 的前台触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!