vikeri/react-native-background-job

Job not triggered

Opened this issue · 3 comments

What am I doing wrong? This is not inside a component. I want to push a notification everytime the interval set by the user is reached.

export default function scheduleRoutine(routine) {
  const message = routine.message === '' ? 'Lembrete automático' : routine.message;

  BackgroundJob.register({
    jobKey: routine.cod.toString(),
    job: () => {
      if (validateSchedule(routine)) {
        PushNotification.localNotification({
          title: `Sua rotina: ${routine.name}`,
          message: message,
          vibration: 900,
          invokeApp: true,
          date: new Date(Date.now() + routine.interval * 60000),
          id: JSON.stringify(routine.cod),
          userInfo: {id: JSON.stringify(routine.cod)},
        });
        cancelNotification(routine);
      };
    }
  });
  console.log('Registered Job: ', routine.cod);

  BackgroundJob.schedule({
    jobKey: routine.cod.toString(),
    period: routine.interval * 60000,
    exact: true,
    allowWhileIdle: true,
  });
}

Yeah, job is not triggering. I have done all the required setup.

import BackgroundJob from "react-native-background-job";

const regularJobKey = "regularJobKey";

BackgroundJob.register({
    jobKey: regularJobKey,
    job: () => console.log(`Background Job fired!. Key = ${regularJobKey}`)
});

export default class Test extends Component {
   state={
      loading: false
   }

   componentDidMount(){
      BackgroundJob.schedule({
            jobKey: regularJobKey,
            notificationTitle: "Notification title",
            notificationText: "Notification text",
            period: 15000
        });
   }

   render(){
       return(<></>);
   }
}

Can you try adding a foreground service permission to the AndroidManifest.xml?
https://developer.android.com/guide/components/foreground-services#request-foreground-service-permissions

@prajna-h Check period key of object
min interval should be 15min

  var backgroundSchedule = {
        jobKey: "myJob",
        exact:true,
        allowWhileIdle :true,
        notificationText :"test",
        notificationTitle :'titel',
        period:900000
        
    }

    BackgroundJob.schedule(backgroundSchedule)
        .then(() => console.log("Success"))
        .catch(err => console.err(err));