react-native-background-timer
react-native-background-timer copied to clipboard
Not working for background geolocation after 3 minutes
Good evening - I've managed to get this library working in an app when building with the Debug scheme, but as soon as I switch to --configuration Release the functionality does not work. I have a debug log in my app that logs data from each interval so I can see it stopping and starting when the app is put in the background. Again, no problem with the debug scheme, just release scheme. I'm looking for any ideas on how to fix.
Actually, it doesn't work for me in release or debug, unless I play a silent audio in the background. If I don't play an audio in the background the process terminates after 3 minutes on iOS, and is inconsistent on android as well. I need to get geolocation and send it to a server once per minute, and my app has been approved to use location services in the background by Apple.
If i do play a sound in the background it keeps the timer going indefinitely up until the user plays audio in another app, after which it has 3 minutes until it stops again.
I think the issue is with the navigator.geolocation spec that react native uses not conforming to Apple's background location specifications. Has anyone gotten a background timer working consistently along the lines of what I'm describing, either with this module, others, or a combination?
Hello, same issue goes for me... Any ideas ?
Since my last post I've learned that the silent audio is only needed when the device is unplugged from power. When it's plugged in I can get a consistent, unending background task working on my iOS device. Ultimately, I switched my app to use transistorsoft's react-native-background-geolocation library on iOS, but continue to use this one on Android. That library has a built in "preventSuspend" feature and also provides metadata about when the device is plugged in or not, and much more. The silent audio is still necessary, but I set it up to play only when the device is not plugged in and stop when it is plugged in. It also seems that the way I have it set up over there the silent audio does not interfere with or get terminated by other apps playing audio.
Any ideas about how to fix it?, I'm having the same issue, after 3 minutes the timer stop working
@kevin1992 : You may have a try on latest version 2.1.1 I've just tested where after 3 minutes the timer is still running
Hey. I have same problem. My application was stop after 3 minutes after lock my phone.
I resolve this, but is not very well solution because when I close or minimize app this starting automatically because I use startActivity
. I looking for other method which wake up my application, but not starting application maybe you have other solution?
I create service WakeUpService in java.
package com.parkingi;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class WakeUpService extends Service {
public WakeUpService() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Intent intentApp = new Intent(this, MainActivity.class);
intentApp.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentApp);
return Service.START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
this service is starting from MainApplication.java via this method which I call in onCreate method
public void wakeUpApp (Context context) {
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, WakeUpService.class);
PendingIntent intentService = PendingIntent.getService(context, 0, intent, 0);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime() + 60 * 1000, 60 * 1000, intentService);
}
My all mechanics is in react-native
@bportman Hello
Can you share me your code? I have similar project and problem :( I wasn't fixed..
@DevQuayle Hey My Andorid devices working well but IOS devices still not working when app goes to background. IOS Simulator ok, working well but devices not :( Did you solve this problem?
@DevQuayle Hey My Andorid devices working well but IOS devices still not working when app goes to background. IOS Simulator ok, working well but devices not :( Did you solve this problem?
Same issue target device iOS 13. I suggest that simulator works fine because of a connected debugger. Stop debug mode and you'll see that it's not working.