Handling incoming notifications when the app is not in the foreground (not supported in Expo Go)

SDK Version: 43 (Managed)
Platforms: Android & IOS
Notification service: Expo notifications (front-end) & expo-server-sdk (back-end) - not using FCM and APN

Hey guys,
I am failing to get the background notifications wake the app up and pass on data (notification payload) to the app. here are the steps:

1- Added the UIBackgroundModes (app.config.js) to: ios: {

infoPlist: {

UIBackgroundModes: [
“remote-notification”,
“fetch”
]
}
},

2- Added the BACKGROUND NOTIFICATION TASTK in the root component file outside the component scope:

// Notify when app is backgrounded
const BACKGROUND_NOTIFICATION_TASK = ‘BACKGROUND-NOTIFICATION-TASK’;

const notify = async(object) =>{
const [notification, setNotification] = useRecoilState(notificationState);
}

TaskManager.defineTask(BACKGROUND_NOTIFICATION_TASK, ({ data, error, executionInfo }) => notify(data.notification)); // THIS FUNCTION DOES’NT RUN which means that the task doesn’t get triggered at all.

Notifications.registerTaskAsync(BACKGROUND_NOTIFICATION_TASK);

3- Backend (expo-server-sdk)
Added the ‘“content-available”: 1’ to the message. I saw someone saying that ‘“content-available”: 1’ only works with APN not expo push notification service?

      messages.push({
        to: pushToken,
        sound: mute.includes(pushToken) ? null : "default",
        title: data.title,
        body: data.body,
        priority: "high",
        data: {"storyId": data.storyId, "content-available": 1},
      });

Please note:
1- Tested it in standalone app build as well as within the ‘production’ env of Expo go app.
2- The ‘Background refresh’ is on - so it shouldn’t be cause either.

Thank in advance!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.