Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

How to add button in push-noitifications to iOS devices with react-native-firebase?

$
0
0

I have a doubt and I am not able to solve the problem of having buttons to perform an action (accept or reject) within a push-notification in iOS with react-native-firebase. For Android I can do it but for iOS I can't find a way to register the action. Next I show how is the code I have.

const notificationListener = () => {
  firebase.notifications().onNotification((notification) => {
    const localNotification = new firebase.notifications.Notification({
        sound: 'default',
        show_in_foreground: true,
      })
      .setSound('default')
      .setBody(notification.body)
      .setData(notification.data)
      .setTitle(notification.title)
      .setSubtitle(notification.subtitle)
      .setNotificationId(notification.notificationId);
    if (Platform.OS === 'android') {      
      localNotification
        .android.setBigText(notification.body)
        .android.setSmallIcon('ic_noti_logo_hnc')
        .android.setLargeIcon('ic_launcher')
        .android.setVisibility(firebase.notifications.Android.Visibility.Public)
        .android.setChannelId(CHANNEL_NOTIFICATIONS.CHANNEL_ID)
        .android.setPriority(firebase.notifications.Android.Priority.High);

      if (isEqual(localNotification.data.set_delay_time, "true")){
        // Build an action
        const acceptAction = new firebase.notifications.Android.Action('accept_action', 'default', 'Accept');
        const rejectAction = new firebase.notifications.Android.Action('reject_action', 'default', 'Reject');
        localNotification
          .android.addAction(acceptAction)
          .android.addAction(rejectAction);
      }

    } else if (Platform.OS === 'ios') {
      localNotification
        .ios.setBadge(notification.ios.badge);
    }
    firebase.notifications().displayNotification(localNotification)
      .catch(err => console.error(err));
  });
};

What I intend to do is something similar to what you find with Android but the only thing I found the most is IOSNotification.alertAction.

Could someone guide me with this? From already thank you very much!

Nico.


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>