react-native-background-job icon indicating copy to clipboard operation
react-native-background-job copied to clipboard

Job not triggered

Open luizgallas opened this issue 4 years ago • 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,
  });
}

luizgallas avatar Sep 09 '20 02:09 luizgallas

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(<></>);
   }
}

prajna-h avatar Oct 05 '20 13:10 prajna-h

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

atosh502 avatar Jan 03 '21 03:01 atosh502

@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));

parmarkamlesh avatar Jun 09 '21 07:06 parmarkamlesh