react-native-push-notification / ios

React Native Push Notification API for iOS.
MIT License
734 stars 282 forks source link

Way to Show Local Notification Popup Only Once #322

Open yfng96 opened 2 years ago

yfng96 commented 2 years ago

"@react-native-community/push-notification-ios": "^1.8.0",

Hi, I am trying to create a timer feature using local notifications. The code below works well with no duplicate notification in Notification Center.

BackgroundTimer.runBackgroundTimer(() => {
      setSecs((prevVal) => {
        Platform.OS === 'ios'
          ? PushNotificationIOS.addNotificationRequest({
              id: '21474',
              title,
              body: moment()
                .startOf('day')
                .seconds(prevVal + 1)
                .format('H:mm:ss'),
              badge: 0,
            })
          : PushNotification.localNotification({
              id: 21474,
              tag: title,
              ticker: 'My Notification Ticker', // (optional)
              channelId: '123', // (required)
              channelName: 'Default Notification', // (required)
              largeIcon: '',
              smallIcon: '',
              color: Colors.digital,
              title,
              message: moment()
                .startOf('day')
                .seconds(prevVal + 1)
                .format('H:mm:ss'),
              showWhen: true,
              when: Date.now(),
              allowWhileIdle: true,
              ongoing: true,
              onlyAlertOnce: true,
            });
        return prevVal + 1;
      });
    }, 1000);

output-onlinegiftools

However, the popups keep appearing. Is there any way to show the popup only once? output-onlinegiftools-2

jose-guilherme-ti commented 2 years ago

I have the same problem, using background-timer. Already managed to solve?