GithubHelp home page GithubHelp logo

Comments (25)

gshotwell avatar gshotwell commented on August 23, 2024 3

In case anyone is interested in a workaround, this seems to work for me:

  1. Start background timer in componentWillMount()
  2. Play a silent sound during the time when you want the background timer to be active. This can be something like react-native-sound file which is playing on repeat
  3. Add the following to your info.plist file:
<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>

Note that you should still abide by the apple terms of service, and only do the above if you are in one of their accepted use-cases for background playing. In my case the code inside of the backgorund timer was all related to playing audio so I think I'm okay.

from react-native-background-timer.

st0ffern avatar st0ffern commented on August 23, 2024 2

Ok, here is the iOS docs explained for those who dont want to read them.

Definition: Suspended state = clicking the home button and have the app running in the background (not killed)

When a app is put into Suspended state a applicationWillTerminate will be sendt to the app. This means all running tasks will have 3 minutes to complete before app is put into freeze mode (The app will stop working 100%)

There is exeptions ref: https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
Table 3-1

Every of the sections here required a specified iOS function to be called in order to run under the permissions.
In example you want background GPS running? you can tell iOS a script it should call with lat, long params and then it will have 10 seconds to execute, if it runs longer it will be killed.

react-native-background-timer does not use any of the functions described in the Table 3-1 and that is why the app will be killed after 3 minutes, no matter what you do..

from react-native-background-timer.

rclai avatar rclai commented on August 23, 2024 2

Shouldn't this be in the docs?

from react-native-background-timer.

ancyrweb avatar ancyrweb commented on August 23, 2024 1

Also happens for me on Android.

from react-native-background-timer.

st0ffern avatar st0ffern commented on August 23, 2024 1

I find all this very hacky solutions, and what i said over a year ago.
This breaks with the iOS policy 😉

from react-native-background-timer.

tconroy avatar tconroy commented on August 23, 2024

is this only occurring on-device? I'm testing in the iOS simulator and it continues to work even while locked.

from react-native-background-timer.

st0ffern avatar st0ffern commented on August 23, 2024

@tconroy it is on device not working. simulator is working.
If you read the Apple TOS on background processes you will see why 😉

@Rewieer what android sdk version? i got it working here.

from react-native-background-timer.

ancyrweb avatar ancyrweb commented on August 23, 2024

Here it's Android 5.0.
So far i've read that handlers can't keep working on sleep mode as it's running on UI Thread. It seems it's required to wake the device to keep performing services.

from react-native-background-timer.

aamir-munir avatar aamir-munir commented on August 23, 2024

Hi,

I am having same issue but it stops even iPhone is not locked, if someone have a solution please comment on this:
#23

from react-native-background-timer.

st0ffern avatar st0ffern commented on August 23, 2024

It violates the iOS app terms, and it is not possible to run a background task in iOS.
You will need to use one of the features for background service calls.
They require special permissions and they will not work with script. they will be called with native functions.

@itcurves #23 have nothing to do with this issue 😖

from react-native-background-timer.

aamir-munir avatar aamir-munir commented on August 23, 2024

ok I am trying to understand it, sorry I post the wrong number it was #22 (sorry about that) but if you check #22 I add the log and that log shows it was running in the background for at least 2 and half minutes and stops after that.

Any other guide please that I can follow?

from react-native-background-timer.

st0ffern avatar st0ffern commented on August 23, 2024

https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:

Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services. Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.

from react-native-background-timer.

st0ffern avatar st0ffern commented on August 23, 2024

This means... react-native-background-timer will not work in iOS

from react-native-background-timer.

aamir-munir avatar aamir-munir commented on August 23, 2024

@Stoffern Thank you and I already check that link and it really helped me as I lie between one of the category and test going well for now, and for my app I do not even need timer as I had a recursive function that runs automatically based on a reply and wait for at least a minute for second api call.

Thanks again for you reply.

from react-native-background-timer.

theonlinenerd avatar theonlinenerd commented on August 23, 2024

hi anybody solve this? My app suspended after 3 minutes and never execute again.

any suggestions please?

from react-native-background-timer.

st0ffern avatar st0ffern commented on August 23, 2024

@theonlinenerd that is normal.. read iOS docs...

from react-native-background-timer.

ancyrweb avatar ancyrweb commented on August 23, 2024

It is normal in the sense it is to be expected from the doc point of view. But it is not normal on the programming point of view : he programmed it to keep working on background.
So, I believe he's asking how to make this work as expected ?

I'm not working on IOS, i'm sorry I can't help.

from react-native-background-timer.

theonlinenerd avatar theonlinenerd commented on August 23, 2024

@Stoffern I am using table 3-1 and using it as fetch now in the focus it is explained it will wake the application to fire whatever written.

If this is the case still this timer will not run ?

Thank you and will appreciate any help or direction I have to follow.

from react-native-background-timer.

st0ffern avatar st0ffern commented on August 23, 2024

It is explained on the page if you read everything under the paragraph that is about the service you use.

from react-native-background-timer.

st0ffern avatar st0ffern commented on August 23, 2024

It is in the iOS docs, the repo just claims a feature that does not work in real life.

from react-native-background-timer.

bportman avatar bportman commented on August 23, 2024

Hey I used @gshotwell's workaround above and it works great when nobody is using their device. We send location heartbeats to a server to track people's arrival and departure from a job site. Unfortunately, if the user plays audio in other apps on the device it will pause the silent background audio and lead to the app being put to sleep by the OS. Do we have a workaround that works consistently and doesn't require playing a silent audio? This is critical for my app.

from react-native-background-timer.

bportman avatar bportman commented on August 23, 2024

Completely agree - that's why I am trying to find a solution that doesn't use silent audio. Apple clearly states on their developer docs that background location services are an approved function of a background task, and my app in the app store has been approved with background modes - location services enabled. The issue seems to be (at least I suspect) that react native's built in geolocation polyfill does not comply with Apple's guidelines for running a background location task. This in spite of the fact that the react native docs seem to suggest it should work.

from react-native-background-timer.

shafiqshams avatar shafiqshams commented on August 23, 2024

Not working

from react-native-background-timer.

saif0347 avatar saif0347 commented on August 23, 2024

@gshotwell your solution worked for me as well. Not only device lock but it also works when app is closed/minimised in iOS.

from react-native-background-timer.

cksiow avatar cksiow commented on August 23, 2024

In case anyone is interested in a workaround, this seems to work for me:

  1. Start background timer in componentWillMount()
  2. Play a silent sound during the time when you want the background timer to be active. This can be something like react-native-sound file which is playing on repeat
  3. Add the following to your info.plist file:
<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>

Note that you should still abide by the apple terms of service, and only do the above if you are in one of their accepted use-cases for background playing. In my case the code inside of the backgorund timer was all related to playing audio so I think I'm okay.

Thanks, this fix the issue, I believe because of sound play, OS will not suspend the thread.

from react-native-background-timer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.