Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 : Run a background service with cordova

I use Ionic 2 and I want to my app do some task when the app is closed. Something like Gmail who continue to notify all the time.

I found this : https://ionicframework.com/docs/v2/native/background-mode/

But I want to create a specific service with specifics method who run in background. This plugin all the application run in background.

Someone can explain me how to do that ?

like image 359
V. Pivet Avatar asked Feb 08 '17 13:02

V. Pivet


People also ask

Is ionic still Cordova?

When people talk about Ionic Framework, they often put it in the “Cordova” or “Angular” buckets, because historically that's what Ionic was: a UI kit for Cordova and Angular apps. That was fine for the first few years of Ionic's life, but up to around 2018 things started changing.

Why Cordova is used in ionic?

Ionic provides frameworks to use in the application. Whereas Cordova provides plugins to run the application similar to the native app. Ionic provides many different functions, which need to be integrated with the application, whereas Cordova provides the hardware access of a device to the application.

Can I use Cordova background mode with Ionic 5/angular?

This tutorial will cover an example use case of the Cordova background mode plugin with Ionic 5/Angular (previously Ionic 3). We'll see how you can keep your app running while it's in the background (minimized).

Can I use Cordova plugins in Ionic 2?

There's been a lot of confusion around how to use Cordova plugins in Ionic 2, and I think a lot of that stems from ngCordova. This was a great little tool that simplified using native plugins in Ionic 1, it can not be used with Ionic 2.

Is it possible to use background services in an ionic application?

But in a hybrid application like built-in Ionic framework, we have some limitations to do that as the applications are not that flexible to use background services or any broadcasts attached to some working threads. In Ionic, luckily we have a Cordova Plugin, which helps in doing this to some extent.

How to use non ionic native plugins in Ionic 2?

The way in which you use a non Ionic Native plugin in Ionic 2 is the same as the way you would use it in any Cordova project, which is however the plugin’s documentation says you should use it. However, there are some extra steps you need to take because TypeScript will cause some problems.


1 Answers

I wanted to keep to received notifications when app is closed. I try a solution : Use Push Notification, Firebase for Android and APNS for iOS. This solution works but with 2 problems :

  • Have to use external services

  • It can be a little bit hard to configure

I hope this can help. I know I don't explain how we can have a service to run in background ... But that is the solution for my problem.

like image 111
V. Pivet Avatar answered Nov 10 '22 16:11

V. Pivet