16.7 C
Thursday, February 15, 2024

ios – React Native Expo Error : Invalid shopper argument – Should conform to EXTaskConsumerInterface protocol

I’m encountering an error in my React Native utility that states “Potential Unhandled Promise Rejection (id: 0): Error: Invalid shopper argument. It have to be a category that conforms to EXTaskConsumerInterface protocol.” This error happens throughout execution, and I am struggling to know its root trigger and the right way to resolve it.

There may be additionally the issue that the notifications aren’t working when testing my app whether or not by means of the expo app or growth construct. My objective was to ship a push notification on the time specified by the consumer.

Error Message:

Potential Unhandled Promise Rejection (id: 0):
Error: Invalid `shopper` argument. It have to be a category that conforms to EXTaskConsumerInterface protocol.
Error: Invalid `shopper` argument. It have to be a category that conforms to EXTaskConsumerInterface protocol.
    at assemble (native)
    at apply (native)
    at _construct (
    at Wrapper (
    at assemble (native)
    at _createSuperInternal (
    at name (native)
    at CodedError (

Following is what I attempted to this point.

Right here is the code for the background duties file:

import { sendPushNotification, useNotification } from "app/companies/notifications"
import * as BackgroundFetch from "expo-background-fetch"
import * as TaskManager from "expo-task-manager"

export const BACKGROUND_FETCH_TASK_NOTIFY = "background-remote-notification"

TaskManager.defineTask(BACKGROUND_FETCH_TASK_NOTIFY, async ({knowledge, error}) => {
  else if(knowledge){
  const now = Date.now()

  console.log(`Received notification background fetch name at date: ${new Date(now).toISOString()}`)

  strive {
    const { expoPushToken } = useNotification(); // Use useNotification hook right here to get the expoPushToken

    if (expoPushToken) {
      await sendPushNotification(expoPushToken.knowledge);
    } else {
      console.log("Expo push token not accessible.");
  } catch (error) {
    console.error("Error dealing with background fetch process:", error);


  // return BackgroundFetch.BackgroundFetchResult.NoData

export async perform registerNotificationsAsync(notificationTime: Date) {
  strive {
    console.log("Notification process initiation")
    // Calculate the time till the subsequent user-defined time
    const now = new Date()

    let timeDiff = notificationTime.getTime() - now.getTime()
    if (timeDiff < 0) {
      timeDiff += 24 * 60 * 60 * 1000 // If the time has handed right now, schedule for tomorrow

    console.log("warn 5")

    return BackgroundFetch.registerTaskAsync(BACKGROUND_FETCH_TASK_NOTIFY, {
      // minimumInterval: 1 * 60, // 1 minute
      minimumInterval: Math.spherical(timeDiff / (1000 * 60)),
      stopOnTerminate: false, // android solely,
      startOnBoot: true, // android solely
  } catch (error) {
    console.error("Error in registerNotificationsAsync", error)
    throw error

export async perform unregisterBackgroundFetchAsync(taskName: string) {
  console.log("Background fetch process unregister initiated")
  if(await TaskManager.isTaskRegisteredAsync(taskName)) {
  return BackgroundFetch.unregisterTaskAsync(taskName)
    console.log("Background fetch " + taskName + " not registered")

Right here is the code for the the place the duty license plate known as:

import { BACKGROUND_FETCH_TASK_NOTIFY, registerNotificationsAsync, unregisterBackgroundFetchAsync } from "app/utils/backgroundTasks";
import { varieties } from "mobx-state-tree";

export const SettingsStoreModel = varieties
  .mannequin("SettingsStore", {
    isNotificationsEnabled: varieties.elective(varieties.boolean, false),
    notificationTime: varieties.elective(varieties.Date, new Date(8).setHours(17,0,0,0)), // default time is 5 PM
  .actions((self) => ({
    toggleNotifications() {
      self.isNotificationsEnabled = !self.isNotificationsEnabled;
      console.log("Notifications modifications to "+ self.isNotificationsEnabled)
      if (registerNotificationsAsync && self.isNotificationsEnabled) {
      } else if (unregisterBackgroundFetchAsync) {
    setNotificationTime(time: Date) {
      self.notificationTime = time;
      console.log("Notification time modifications to "+ self.notificationTime)

Utilizing the above logic, I may name toggle Notification or setNotificationTime with a view to register for the background process. Besides this isn’t what is going on and I can not seem to discover a resolution on-line.

I am utilizing Expo for my React Native venture, and it looks like there is likely to be a difficulty associated to the shopper argument and its conformity to the EXTaskConsumerInterface protocol. Nonetheless, I am unsure about the right way to examine and resolve this difficulty. Any steerage or insights into this error can be vastly appreciated. Thanks!

Latest news
Related news


Please enter your comment!
Please enter your name here