DEV Community

Discussion on: Show Notifications in Foreground on Expo iOS Application!!

Collapse
 
feliperaul profile image
flprben • Edited

Nice tip Michael! I just wanted to add something that was not immediately obvious for me.

To handle the click on that local notification, the code is already set up, since the Notifications.addListener(callback) will be fired when you tap that local notification. The only difference is it will have a remote: false property.

So, what we're doing in our app, is we pass a data params to that local notification to know what we should do:

_handleNotification = async notification => {                                                                                    
  if (notification.remote) {
    Vibration.vibrate();                                                  
    const notificationId = Notifications.presentLocalNotificationAsync({      
      title: "Follow @technoplato",  
      body: "To learn yourself goodly (also follow PewDiePie)",                                             
      ios: { _displayInForeground: true } 
      data: {arbitraryDataFromTheOriginalNotification: notification.arbitraryDataFromTheOriginalNotification}                               
    });                                                                       
  } else {
     // Here you handle the local notification tapped, and you can access notification.data.arbitraryDataFromTheOriginalNotification
  }
};              

That way, when that notification is tapped, the