transistorsoft / react-native-background-fetch

Periodic callbacks in the background for both IOS and Android
MIT License
1.43k stars 191 forks source link

BGTaskSchedulerErrorDomain error1 on iOS #447

Closed krisidmisso closed 1 year ago

krisidmisso commented 1 year ago

Your Environment

const status: number = await BackgroundFetch.configure(
      {
        minimumFetchInterval: 15, // <-- minutes (15 is minimum allowed)
        stopOnTerminate: false,
        enableHeadless: true,
        startOnBoot: true,
        // Android options
        forceAlarmManager: false, // <-- Set true to bypass JobScheduler.
        requiredNetworkType: BackgroundFetch.NETWORK_TYPE_NONE, // Default
        requiresCharging: false, // Default
        requiresDeviceIdle: false, // Default
        requiresBatteryNotLow: false, // Default
        requiresStorageNotLow: false, // Default
      },
      async (taskId: string) => {
        console.log('[BackgroundFetch] taskId', taskId);
        // Create an Event record.
        const event = await Event.create(taskId, false);
        // Update state.
        setEvents(prev => [...prev, event]);
        // Finish.
        BackgroundFetch.finish(taskId);
      },
      (taskId: string) => {
        // Oh No!  Our task took too long to complete and the OS has signalled
        // that this task must be finished immediately.
        console.log('[Fetch] TIMEOUT taskId:', taskId);
        BackgroundFetch.finish(taskId);
      },
    );

Expected Behavior

The task should be scheduled and triggered like it does in Android.

Actual Behavior

When scheduling a task I get an error inside catch(): The operation couldnt be completed. (BGTaskSchedulerErrorDomain error1.)

Steps to Reproduce

  1. Used same Component as in Example app:

    const onClickScheduleTask = () => {
    BackgroundFetch.scheduleTask({
      taskId: 'com.transistorsoft.customtask',
      delay: 5000,
      forceAlarmManager: true,
    })
      .then(() => {
        Alert.alert('scheduleTask', 'Scheduled task with delay: 500ms');
      })
      .catch(error => {
        Alert.alert('scheduleTask ERROR', error);
      });
    };
  2. Tap scheduleTask

  3. Alert with error message is displayed

Context

I have added the identifiers in XCode: image

AppDelegate.m: image image

Debug logs

christocracy commented 1 year ago

BGTaskSchedulerErrorCodeUnavailable

Screenshot 2023-05-08 at 1 31 57 PM