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

background timer not running in ios 12.3 version

Open SwathyPA opened this issue 6 years ago • 6 comments

in 12.3 version ios timer is not running in background

SwathyPA avatar Jun 22 '19 06:06 SwathyPA

Hi @SwathyPA I'm using iOS 12.3.1 and works well.

skantus avatar Jun 28 '19 23:06 skantus

can I get a basic code of yours

SwathyPA avatar Jun 29 '19 06:06 SwathyPA

Hi @SwathyPA, you can try in 2 ways:

Same code:

BackgroundTimer.runBackgroundTimer(() => { 
  // Your scheduled task.
}, 
3000);

BackgroundTimer.stopBackgroundTimer(); //after this call all code on background stop run.`

Selecting the platform:

 startDownloadsInBackground = () => {
    Platform.select({
      ios: () => {
        BackgroundTimer.start();
        // Your scheduled task.
      },
      android: () => {
        this.backgroundTimer = BackgroundTimer.setTimeout(() => {
        // Your scheduled task.
        }, 0);
      }
    })();
  };

  stopDownloadsInBackground = () => {
    Platform.select({
      ios: () => {
        BackgroundTimer.stop();
      },
      android: () => {
        BackgroundTimer.clearTimeout(this.backgroundTimer);
      }
    })();
  };

Note:

For security reasons the task is blocked after 3 minutes, I hope this will fixed.

https://github.com/ocetnik/react-native-background-timer/issues/125

I hope it helps!

skantus avatar Jun 29 '19 12:06 skantus

For security reasons the task is blocked after 3 minutes...

What does that mean @skantus? Is that an Android thing or something limited in this codebase?

If I'm understanding right, if I set a timer and want to do something exactly 4 minutes later, then that is not possible?

alexfinnarn avatar Sep 06 '19 15:09 alexfinnarn

Hi, @alexfinnarn this is a similar issue about background task to a better understanding:

https://github.com/EkoLabs/react-native-background-downloader/issues/42#issuecomment-527653821

skantus avatar Sep 07 '19 09:09 skantus

Hi @SwathyPA I'm using iOS 12.3.1 and works well.

Could you please share your working code, please? My task is to send my position every 15 minutes

eyale avatar Jan 31 '20 13:01 eyale