Reputation: 1
hi as I would like to be able to run some code when the app is closed (for closed I mean closed by the task manager). my app must be able to make http requests via axios in the background on both android and ios (must send notifications using the local-notification plugin that reminds that one or more events in an external calendar will start in an hour), I searched in network and I saw the documentation but it is not clear how I should do, I also read that the way to run background code on android 8 changes radically. Can someone explain to me what I have to do? what permissions should I request from the system? or if there is any example of code on the net.
Upvotes: 0
Views: 1852
Reputation: 3138
Okay you should use a service in Android. It's a simple class that makes it happen in the background and after you're done you can stop the service. It works for android up to API v26 api. (26 not included). Documentation
For >=26 you can use Managers. There's a downloadManager already. But you don't have to use it, you can also use a Job Scheduler (>=lollipop). There's a nice tutorial about it here.
Also, read about using Android Background Services in NativeScript here.
Upvotes: 1
Reputation: 21908
Here are the samples for implementing background services for iOS & Android.
There is also a plugin nativescript-background-fetch which might work for you.
tns plugin add nativescript-background-fetch
Invokes your callback function roughly every 15 mins while the app is not alive, so you could finish your background activities like downloading your content etc.,
Upvotes: 2