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

Passing variables to the job function?

Open brentluna opened this issue 7 years ago • 4 comments

Is there anyway to pass variables to the job function? Was hoping to use this lib for running a timer in the background which has a time determined by the user, as well as send a post request to a user assigned address.

brentluna avatar May 30 '17 01:05 brentluna

I don't think I understand, what data would you like to have passed to js from native?

vikeri avatar May 30 '17 07:05 vikeri

I was trying to create an app that has a timer/alarm that the user can select a duration and after that time expires I send a http request to a user selected address. I was looking at this lib to try and make sure it happens even if the app is in the background or closed. So basically was trying to create the job function to accept a user provided URL for the http request and a duration for a setInterval

brentluna avatar May 30 '17 14:05 brentluna

Ok, you can't pass parameters to the native function, but you can store the url in eg. AsyncStorage or Realm, and then when the timer is triggered you just fetch the url and trigger it. Would that work?

vikeri avatar May 30 '17 15:05 vikeri

Sounds like it should work for the url aspect, the timer aspect I'm still unsure about. How could i only trigger the http request after a user specified time? I noticed the job.period param, but from the description it sounds like it woudl trigger the job immediatley and then that is only a delay for subsequent triggers.

brentluna avatar May 30 '17 16:05 brentluna