Someone has tried the bgs-core plugin for background services?

I have been looking for a few days ago a plugin that allows me to execute a service in the background every x time and that I execute a fragment of code (for example a call ajax).

I have found the following plugin for cordova that allows you to create a background service with which you could get what I want, make an ajax call every 20 minutes and do something depending on what the json returns (for example return an local notification).

Do you think I could implement it in Ionic something similar using this plugin?

I’ve tried the example they have mounted on cordova and it seems to work

I’m also looking into using this for running some background operations. I don’t see why it wouldn’t work with Ionic, it is just a Cordova application underneath the hood. Please update this thread with how things work out for you.

On behalf of users who like their batteries to last more than half an hour, please don’t do this. Asleep should mean asleep.

1 Like

so many applications do the same, isn’t?

None that I would ever consider installing.

I can make you a question? Do you know how import a third party library from Cordova to Ionic? Im completly lost

I explained it to you:

Multiple times.

Yes, i know, but when i try to implement always obtain an error or i cannot do the import. I also try this with NPM and i cannot find the name module.

https://www.npmjs.com/package/cordova-plugin-bgs-core

I’m completly lost with this, i’ve lost too many days trying to implement this and i don’t know how i can do

What error?
Why can’t you do what import?

You noticed this bit on the plugin you are trying to use?

The functionality is not a complete plugin - it is intended to be extended by developers to create their own background service.

Why do you need this plugin at all? What problem are you trying to solve?

I do “npm i cordova-plugin-bgs-core --save” and then i cannot do the import… Y tried import * from ‘cordova-plugin-bgs-core’ and ‘com.red_folder.phonegap.plugin.backgroundservice’. I tried doing: declare var cordova:any; and then cordova.pluginscom.red_folder.phonegap.plugin.backgroundservice.sample.enable(). Not worked for me. These are the installed plugins <plugin name="com.red_folder.phonegap.plugin.backgroundservice" spec="git+https://github.com/Red-Folder/bgs-core.git" />

I’m trying to do a background service when the app is closed to execute an http callback into a Json to check locally if i have changes in that json each hour

By the way i’m trying to use the example who is in the docs.

That would not be the way to do it, as I described in the other topic. Read it.

Also:

Why don’t you just use Background Fetch - Ionic Documentation?

Because this plugin it’s only for IOs… I used that plugin but in ios mode, but in Android i can’t use that. I understand the other way you explained in the other post, but when i try to do this i get an error: import { myService } from ‘com.red_folder.phonegap.plugin.backgroundservice.sample’; i get an error

You didn’t understand.

Cordova plugins are never imported in .ts code. You just make the global variable accessible by using the declare, see my other post.

You say in the another post: after you imports… What import? Thanks for the help. You can do a little plnkr or something?

A .ts file has imports. Put the code I posted after these, next line.

Ok i think i got it, now i need to reescribe all the functions but i can see my service working now

i do it with a declare… Now i need to know how fire an event each “x” seconds to show an alert or something

Create a new topic for that please. These 2 are already a mess, talking about the same thing in two places.

@temohpab was you able to use the cordova plugin in ionic?