反应原生推送通知(Android) - 通知不断重复并且不会停止 [英] react native push notification (Android) - notification keeps repeating and wont stop

查看:230
本文介绍了反应原生推送通知(Android) - 通知不断重复并且不会停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 react-native-push-notification 库.我可以让通知与振动和声音一起出现.....但是问题是它不断重复并且不会停止.

I am using react-native-push-notification library. I am able to make notification appear along with vibration and sound.....however problem is that it keeps repeating and wont stop.

我快速连续收到 20 多个相同的通知.有人知道为什么会这样吗?

I get 20+ of the same notification in quick succession. Anyone know why this is happening?

见下面的代码

import PushNotification from 'react-native-push-notification';

  constructor(props) {
    super(props);

    PushNotification.configure({
      onNotification: function(notification) {
        console.log('NOTIFICATION:', notification);
        notification.finish(PushNotificationIOS.FetchResult.NoData);
      },

      popInitialNotification: true,
      requestPermissions: true,
    });

runPushNotification = () => {
    PushNotification.localNotification({
     title: 'title'
     message: 'message',
     playSound: true,
     soundName: 'sound.mp3',
     autoCancel: true, 
     vibrate: true, 
     vibration: 300, 
     actions: '["Yes", "No"]',
     onlyAlertOnce: true,
    });
  };

推荐答案

对于未来的查看者,如果您收到通知,有两种方法可以这样做,作为来自外部服务器的推送通知,或创建的本地通知来自您的应用自己的代码.

For future viewers, if you are getting a notification there are 2 ways to do so, either as a push notification from an external server, or a local notification created from your apps own code.

如果您收到推送通知,那么您需要检查您的服务器端逻辑,以确保您不会多次触发它们.

If you are getting push notifications, then you need to check your server side logic to see that you aren’t firing them too many times.

如果这些是本地通知,请通过您的代码搜索您正在调用通知的任何地方.

If these are local notifications do a search through your code for any place you are calling the notification.

同时执行这两项操作应该会导致它被过度调用.

Doing both of these should lead to where it is being called excessively.

这篇关于反应原生推送通知(Android) - 通知不断重复并且不会停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆