简体   繁体   English

Ionic 2 - 当应用程序在IOS上处于前台时显示通知

[英]Ionic 2 - Show notification when app is in foreground on IOS

I am making a chat application in Ionic 2. I want notifications to appear even when app is in foreground. 我正在Ionic 2中创建一个聊天应用程序。即使应用程序位于前台,我也希望显示通知。 I have tried using Phonegap Plugin Push and FCM Plugin both and I'm getting notifications when app is in background and when app is killed. 我尝试过使用Phonegap插件推送和FCM插件,当应用程序处于后台并且应用程序被杀时我收到通知。

But these plugins didn't show notifications when app is in foreground. 但是这些插件在app处于前台时没有显示通知。 So I used Local Notifications Plugin by Katzer. 所以我使用了Katzer的Local Notifications Plugin。 It works for Android perfectly but in IOS I'm facing multiple issues. 它完全适用于Android,但在IOS我面临着多个问题。

When used with Phonegap Plugin Push, the local notification does appear but its click event does not work. 与Phonegap插件推送一起使用时,会显示本地通知,但其单击事件不起作用。 Also, the two plugins seem to have some conflicts so when used together, sometimes normal push notifications does not arrive or their click events does not work. 此外,这两个插件似乎有一些冲突,所以当一起使用时,有时正常的推送通知不会到达或他们的点击事件不起作用。 When used with FCM plugin, no local notification arrived. 与FCM插件一起使用时,没有到达本地通知。

I also tried using phonegap-plugin-local-notification but again it worked for Android but in IOS, notification arrives in form of alert and also its click event gets called automatically. 我也尝试过使用phonegap-plugin-local-notification但是它又适用于Android,但是在IOS中,通知以警报的形式到达,并且它的点击事件也会被自动调用。

I am stuck on this for a long time. 我坚持了很长时间。 Can someone please provide a solution? 有人可以提供解决方案吗? All I want is to get notification in the notification center when app is in foreground in IOS and also a click event so I can do redirection on click. 我想要的只是当应用程序在IOS中处于前台时在通知中心收到通知以及点击事件,这样我就可以在点击时进行重定向。

Any help would be appreciated. 任何帮助,将不胜感激。

I was implementing in my cordova app this plugin . 我在我的cordova应用程序中实现了这个插件

And when device ready I fired this code: 当设备准备就绪时我解雇了这段代码:

pushNotification.register(
function (result) {
    //Do some stuff
}, function (error) {
    //Do some stuff on error 
}, {
    "badge":"true",
    "sound":"true",
    "alert":"true",
    "ecb": "onNotificationAPN"
});

And also implemented below function: 并且还实现了以下功能:

function onNotificationAPN(event) {
  if (event) {
    if ( event.alert ) {
      alert(Recieved alert: + event.alert);
    }
    if ( event.sound ) {
      var snd = new Media(event.sound);
      snd.play();
    }
    if ( event.badge ) {
      pushNotification.setApplicationIconBadgeNumber(function() {
        //SetApplicationIconBadgeNumber success.
      }, function() {
        //SetApplicationIconBadgeNumber error.
      },
      event.badge);
    }
  }
}

And I am able to receive notifications also in foreground. 我也可以在前台收到通知。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ios 10,当应用程序处于前台时,即使使用UNNotificationPresentationOptionAlert,也不会显示通知警报 - ios 10 when app is in foreground no notification alert is show even with UNNotificationPresentationOptionAlert iOS 10,本地通知会在应用程序处于前台时显示? - iOS 10, Local notification show when app is in foreground? 当应用程序为前台时如何显示本地通知 - How to show local notification when app is foreground 应用程序在前台时未触发通知-iOS - Notification not triggered when app in foreground - iOS 在iOS应用中显示通知,而应用在前景中显示/在Swift 3中处于活动状态 - Show notification in iOS app While app in foreground / Active in swift 3 对于本地通知,当应用程序在前台运行时,如何显示“警报”? - For Local Notification, how to show a “Alert” when the app is running in the foreground? Flutter Firebase 如何控制通知在应用程序处于前台时不显示 - Flutter Firebase how to control notification not to show when the app is in foreground Appcelerator:当应用程序在前台时(打开)在通知中心显示推送消息 - Appcelerator: Show push messages in the Notification Center when the app is in the foreground (open) iOS:当应用程序处于前台状态时,如何让用户忽略远程通知? - iOS: how to let the user ignore a remote notification when app is in foreground? 应用程序处于前台时未收到推送通知 ios flutter - Push Notification not received when app is in foreground ios flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM