Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job not triggered #169

Open
luizgallas opened this issue Sep 9, 2020 · 3 comments
Open

Job not triggered #169

luizgallas opened this issue Sep 9, 2020 · 3 comments

Comments

@luizgallas
Copy link

luizgallas commented Sep 9, 2020

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,
  });
}
@prajna-h
Copy link

prajna-h commented Oct 5, 2020

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

@atosh502
Copy link

atosh502 commented Jan 3, 2021

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

@parmarkamlesh
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants