Comments (25)
In case anyone is interested in a workaround, this seems to work for me:
- Start background timer in
componentWillMount()
- 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
- 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.
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.
Shouldn't this be in the docs?
from react-native-background-timer.
Also happens for me on Android.
from react-native-background-timer.
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.
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.
@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.
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.
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.
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.
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.
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.
This means... react-native-background-timer will not work in iOS
from react-native-background-timer.
@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.
hi anybody solve this? My app suspended after 3 minutes and never execute again.
any suggestions please?
from react-native-background-timer.
@theonlinenerd that is normal.. read iOS docs...
from react-native-background-timer.
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.
@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.
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.
It is in the iOS docs, the repo just claims a feature that does not work in real life.
from react-native-background-timer.
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.
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.
Not working
from react-native-background-timer.
@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.
In case anyone is interested in a workaround, this seems to work for me:
- Start background timer in
componentWillMount()
- 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
- 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)
- Can I read and write files?
- The timer works perfectly fine in iOS simulator but not on hardware device HOT 3
- BackgroundTimer stops when app goes to background after Few Sec in IOS React Native IOS HOT 18
- runBackgroundTimer doesn't work on RN 66.3 - Tested on Android HOT 5
- Background service is not working if Background data usage disabled. HOT 1
- Using react-native-background-timer with react-native-web HOT 1
- Terminating app due to uncaught exception NSInternalInconsistencyException HOT 1
- how to get clipboard content on background service
- Testing background timer with useFakeTimers in Jest HOT 4
- Background Action and Graphql HOT 2
- the task is dying out HOT 8
- background task dosen't work when device is in sleep mode. HOT 7
- Is this repo still alive? HOT 5
- BackgroundTimer.clearTimeout does not stop ongoing background task
- Invariant Violation: new NativeEventEmitter() requires a non-null argument., js engine: hermes HOT 1
- react-native-background-timer not working in android HOT 1
- after upgrading gradle version to 8.2.2 I'm getting this error: Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported. HOT 3
- React Native Background Task Termination on Device Lock in Android OS <= 13 HOT 1
- RangeError in long running timers HOT 1
- Problem build/config with MainApplication.kt HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-background-timer.