NEUROFUSIONInc / fusion

Record changes in health, behavior and brain activity - right in your browser or mobile phone. Discord: https://discord.gg/sqsuzXWE3K
https://usefusion.ai/research
GNU Affero General Public License v3.0
34 stars 7 forks source link

Track when notifications are triggered and empty tray #117

Open oreHGA opened 1 year ago

oreHGA commented 1 year ago

I've been battling with this for a while and giving up (for now)

Expo does have documentation for this but it doesn't work for some reason.

I have tried even creating full build because somewhere in the docs, they mention that expo go doesn't work. Something to try later is ensuring that content-available is also set in the payload.

Anyways I'll come back to this later. It is important for the user experience they're not seeing multiple notifications for the same thing

// register task for dismissing older notifications
const BACKGROUND_NOTIFICATION_TASK = "BACKGROUND-NOTIFICATION-TASK";
TaskManager.defineTask(
  BACKGROUND_NOTIFICATION_TASK,
  async ({ data, error, executionInfo }) => {
    appInsights.trackEvent({
      name: "background-notification-triggered",
    });

    appInsights.trackEvent(
      {
        name: "background-notification-triggered",
      },
      {
        data,
      }
    );
    const meta = `${Platform.OS}/${BACKGROUND_NOTIFICATION_TASK}`;

    data && console.log(meta, "data", data);
    error && console.log(meta, "error", error);
    executionInfo && console.log(meta, "executionInfo", executionInfo);
  }
);

await Notifications.registerTaskAsync(BACKGROUND_NOTIFICATION_TASK);

const registeredTasks = await TaskManager.getRegisteredTasksAsync();
console.log("🔵 Registered tasks:", registeredTasks);

// const taskmangerIsAvailable = await TaskManager.unregisterAllTasksAsync();
// console.log("🔵 TaskManager is available:", taskmangerIsAvailable);

Related stack overflow - https://stackoverflow.com/questions/75833193/how-to-set-content-available-1-with-expo-push-api-when-sending-push-notifica