im trying to run a function when the app is in background and the user receives a notification, but doesnt interact with it, to do this im using task manager, since sdk 42 its possible to run a function in background, having this code:
const BACKGROUND_NOTIFICATION_TASK = 'remote-notification';
TaskManager.defineTask(BACKGROUND_NOTIFICATION_TASK, () => {
BackgroundTimer.runBackgroundTimer(() => {
console.log("holalahola");
// schedulePushNotification();
},
2000);
});
Notifications.registerTaskAsync(BACKGROUND_NOTIFICATION_TASK);
this works on android, cause when app is in background and i send a notification the code in the task will executes, but in ios it doesnt, already added in app.json remote-notification
"ios": {
"supportsTablet": false,
"infoPlist": {
"UIBackgroundModes": [
"remote-notification"
]
},
"googleServicesFile": "./GoogleService-Info.plist",
"bundleIdentifier": "com.xxxx"
}
is there a way i can run a function on background or a way to detect background event? using managed workflow and expo, was thinking if its not possible, then in the background just will be fetching every 15min if something happened
I found the solution in this github thread, basically you need to include _contentAvailable: true in your notification payload to expo push notification's service:
Example payload for ios{ to: <push_token>, "_contentAvailable": true}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With