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

How it works?

Open aamir-munir opened this issue 5 years ago • 16 comments

Hi,

I was using react-ntive-background-geo-location to keep my application alive in the background.

But iOS 13 not letting it work anymore. Can I use it with iOS 13? I need it to send a post request every minute to a server is it possible using this component?

Please advise. Thank you

aamir-munir avatar Dec 03 '19 07:12 aamir-munir

I'm using it with mauron85/react-native-background-geolocation It works good now. Tested on Pixel 2 and Samsung S8

eyale avatar Dec 05 '19 14:12 eyale

I'm using it with mauron85/react-native-background-geolocation It works good now. Tested on Pixel 2 and Samsung S8

well. Android is always good for the developer I am talking about iOS

aamir-munir avatar Dec 05 '19 15:12 aamir-munir

Very funny. I had issue only on Android background mod. On iOS I have no issue with background. Anyway on iOS it works good too.

const id = BackgroundTimer.setInterval(tick, delay);
return () => BackgroundTimer.clearInterval(id);

eyale avatar Dec 05 '19 15:12 eyale

are you using in combination with react-native-background-geolocation?

I do not want to use geolocation right now.

Can I use only a timer?

aamir-munir avatar Dec 05 '19 16:12 aamir-munir

I don't reason why you should not.

eyale avatar Dec 05 '19 16:12 eyale

mauron85/react-native-background-geolocation is needed about 300$ for release building android .

not exact. This package is free. But there are transistorsoft/react-native-background-geolocation that is paid one.

eyale avatar Dec 06 '19 07:12 eyale

I don't reason why you should not.

Hello,

sorry for getting back to you late, I just create a test app

componentDidMount() { BackgroundTimer.runBackgroundTimer(() => { console.log('testing'); }, 3000);

}

and even running in the simulator it stops printing after about 20-30 sec.

also tried this:

BackgroundTimer.start(); var time = 0; BackgroundTimer.setInterval(() => { time ++; console.log(time) }, 1000)

same result.

can you please guide me what I am missing?

TIA

aamir-munir avatar Dec 11 '19 02:12 aamir-munir

runBackgroundTimer

BackgroundTimer.setInterval(tick, delay)

eyale avatar Dec 11 '19 07:12 eyale

runBackgroundTimer

BackgroundTimer.setInterval(tick, delay)

If you look at my code I did try that too.

Can you please quickly test on your side?

aamir-munir avatar Dec 11 '19 18:12 aamir-munir

Very strange I'm using BackgroundTimer.setInterval and it's work as is should. I have component that returns null https://reactjs.org/docs/conditional-rendering.html#preventing-component-from-rendering.

function useInterval(callback, delay) {
  const savedCallback = useRef();

  // Remember the latest function.
  useEffect(() => {
    savedCallback.current = callback;
  }, [callback]);

  useEffect(() => {
    function tick() {
      savedCallback.current();
    }
    if (delay !== null) {
      if (IS_IOS) {
        BackgroundTimer.start();
      }
      const id = BackgroundTimer.setInterval(tick, delay);

      return () => BackgroundTimer.clearInterval(id);
    }
    return () => {};
  }, [delay]);
}

And starting it in component

useInterval(
    () => { /* your code here */   },
    run ? delay : null,
  );

eyale avatar Dec 12 '19 08:12 eyale

would you like to connect to look together what we can do to fix it? right now I am stuck and not sure what else needs to be done.

TIA

aamir-munir avatar Dec 13 '19 18:12 aamir-munir

still no success.

aamir-munir avatar Dec 20 '19 05:12 aamir-munir

I think this module should be IOS setting more. IOS 13 kill background service, right? like this: https://stackoverflow.com/questions/57197958/xcode-11-what-is-the-new-background-processing-background-mode

Saehanseul avatar Jan 17 '20 01:01 Saehanseul

I think this module should be IOS setting more. IOS 13 kill background service, right? like this: https://stackoverflow.com/questions/57197958/xcode-11-what-is-the-new-background-processing-background-mode

for now, I have no success with working app in the background in a simulator without debugger too and in build, version it's not working too, but if we have debugger mode, it works perfectly. I suggest that we need to use runBackgroundTimer it consoles every second some info so Iv need to try

eyale avatar Jan 31 '20 12:01 eyale

it not work!!!!!!!!!!!!!!!!!!!!!!!!!!!!! at all

byteab avatar Mar 07 '20 15:03 byteab

no, it does not. and no help at all.

aamir-munir avatar Mar 09 '20 08:03 aamir-munir