Category Archives: Ionic Native

Ionic Background Fetch


Ionic Background Fetch Native Ios – Background fetch is basically IOS api which wakes up your app about every 15 minutes and provides your app exactly 30s of background running time. You can define the callback function which will be called when the background-fetch event will occur. Here in this tutorial we are going to explain how you can install this plugin to use the IOS native background-fetch feature.


Ionic Background Fetch Native Plugin | Install | Example

You can install the background fetch plugin simply as below-

Installation

To install the cordova-plugin-background-fetch plugin run the below command-

Ionic Background Fetch Native Plugin Installation:

$ ionic cordova plugin add cordova-plugin-background-fetch
$ npm install --save @ionic-native/background-fetch

Supported Platforms

  • IOS – This is only supported on Ios.

Example

Here is an example of background fetch –

Ionic Background Fetch Example:

import { BackgroundFetch, BackgroundFetchConfig } from '@ionic-native/background-fetch';


constructor(private backgroundFetch: BackgroundFetch) {

  const config: BackgroundFetchConfig = {
    stopOnTerminate: false, // Set true to cease background-fetch from operating after user "closes" the app. Defaults to true.
  };

  backgroundFetch.configure(config)
     .then(() => {
         console.log('Background Fetch initialized');

         this.backgroundFetch.finish();

     })
     .catch(e => console.log('Some Error during initializing background fetch', e));

  // Start the background-fetch API. Your callbackFn provided to #configure will be executed each time a background-fetch event occurs. NOTE the #configure method automatically calls #start. You do not have to call this method after you #configure the plugin
  backgroundFetch.start();

  // Stop the background-fetch API from firing fetch events. Your callbackFn provided
 backgroundFetch.stop();

}

Instance Members

  • configure(config) – Ccnfigure the plugin’s fetch Callback.
  • start()– Start the background fetch.
  • stop()– Stop the background fetch.
  • finish()– When fetch action is complete.
  • stop()– Returns the background fetch status.

Background Fetch Configuration

BackgroundFetchConfig

  • BackgroundFetchConfig(stopOnTerminate) stopOnTerminate param is boolean, Set true to cease background-fetch.

Ionic Autostart


Ionic Autostart – This plugin is basically used to start the Android Application automatically when device boot or auto-update of application. This is manageable from your app you can enable or disable this from your application. Here in this tutorial, we are going to explain how you can use this native plugin in Ionic.


Ionic Autostart Cordova Plugin Native Example

You can install and use th AutoStrat Plugin simply as below-

Installation

To install the cordova-plugin-autostart run the below command-

Ionic Autostart Plugin Native Example:

$ ionic cordova plugin add cordova-plugin-autostart
$ npm install --save @ionic-native/autostart

Supported Platforms

This plugin is supported in Only following platform-

  • Android

Example

Here is an example of Ionic Android Autostart Plugin

| Example:

import { Autostart } from '@ionic-native/autostart';


constructor(private autostart: Autostart) { }

...

this.autostart.enable();

this.autostart.disable();

Instance Methods

There are basically two instance methods enable and disable let us quickley go through.

  • enable– This is used to enable automatic start on boot.
  • disable– This is used to disable automatic start on boot.

Ionic Appodeal


Ionic Appodeal – Appodeal plugin is basically used to serve ads through the native Appodeal SDKs. Here in this tutorial, we are going to explain how you can install this plugin to use the native Appodeal SDKs.


Ionic Appodeal Syntax | Example

First install the plugin to use it. –

Installation

Install the Cordova and Ionic Native plugins Using the below command-

Ionic Appodeal Install Example:

$ ionic cordova plugin add https://github.com/appodeal/appodeal-cordova-plugin.git
$ npm install --save @ionic-native/appodeal

Supported Platform

This plugin is supported in below platforms-

  • 1. Ios
  • 2. Android

Example

| Example:

import { Appodeal } from '@ionic-native/appodeal';

constructor(private appodeal: Appodeal) {

   const appKey = 'APP_API_KEY';
   appodeal.initialize(appKey, appodeal.AD_TYPES.REWARDED_VIDEO);
   appodeal.show(appodeal.AD_TYPES.REWARDED_VIDEO);

}

Where APP_API_KEY is your App Api Key.

Ionic App Minimize


Ionic App Minimize Plugin App Minimize plugin provides functionality for minimizing the app on Android devices. To use this plugin you need to add the cordova cordova-plugin-appminimize. Here in this tutorial we are going to explain how you can install this plugin and use it.


Ionic App Minimize Plugin Install Example

First you need to install cordova plugin cordova-plugin-appminimize. You can install by adding the following command-

Ionic App Minimize Plugin Install Example :

$ ionic plugin add --save https://github.com/tomloprod/cordova-plugin-appminimize.git
$ npm install --save @ionic-native/app-minimize
  • Supported Platform– Android

Example

| Example:

import { AppMinimize } from '@ionic-native/app-minimize';


constructor(private appMinimize: AppMinimize) { }

...

this.plugin.minimize().then(
  success => console.log('Closed'),
  err => console.log('Something went wrong')
);

Instance Members

  • minimize()– This minimizes the application.

Returns

It Returns the promize.

Ionic App Version


Ionic App Version – Cordova plugin app version is used to get the app version. Here in this tutorial we are going to explain how you can install this plugin and use it.


Ionic App Version | Native App Version Plugin

First, install the cordova plugin cordova-plugin-app-version, you can install this plugin simply as below- –

Ionic App Version | Native App Version Plugin:

$ ionic plugin add --save cordova-plugin-app-version
$ npm install --save @ionic-native/app-version

This plugin reads the app version from the target build.

Supported Platforms

  • Android
  • Ios

Example

You can get the app version details simply as below-

Ionic Get App Version Example

import { AppVersion } from '@ionic-native/app-version';

constructor(private appVersion: AppVersion) { }

...


this.appVersion.getAppName();
this.appVersion.getPackageName();
this.appVersion.getVersionCode();
this.appVersion.getVersionNumber();
  • getAppName– This returns the app name.
  • getPackageName– This returns the app package name.
  • getVersionCode– This returns the app version code.
  • getVersionNumber– This returns the app version number.

Ionic App Update


Ionic App Update Cordova plugin app update is used to do the self update for android. First you need to add plugin cordova-plugin-app-update. Here in this tutorial we are going to explain how you can use Ionic App Update Plugin.


Ionic App Update | Native App Plugin Example

Run the following command to install the app update plugin –

Ionic Install App Update Plugin Command:

$ ionic plugin add --save cordova-plugin-app-update
$ npm install --save @ionic-native/app-update

Supported Platforms

  • Android– This feature is supported only in Android.

This plugin automatically updates the app, let us create a simple example to understand this.

Usage

Step 1

First you need need to create a XML file(update.xml) and host this file on server with the following content-

Ionic App Update XML:


    302048
    APK Name
    https://your-remote-api.com/YourApp.apk

In the above example provide the following details –

  • version – Version number to which you want update.
  • name – Apk file Name.
  • url – Apk file url path.

Step 2

Now you can use the following code to update-

Ionic App Update:

import { AppUpdate } from '@ionic-native/app-update';

constructor(private appUpdate: AppUpdate) {

   const updateUrl = 'http://your-remote-api.com/update.xml';
   this.appUpdate.checkAppUpdate(updateUrl);

}

This plugin will compare the app with the API version if API has newer version then it will automatically install it.

Instance Members

  • checkAppUpdate(updateUrl)– It checks the and performs update action. updateUrl is Update Api URL. It returns promise that resolves when something happens.

Ionic App Rate


Ionic App Rate plugin- App Rate plugin provides functionality to prompt the user to rate the App having the options – Now, Later, Never. App Rate functionality requires the Cordova plugin
cordova-plugin-apprate. Here in this tutorial we are going to explain how to install App Rate plugin and use it.


Ionic App Rate | Plugin | Functionality Example

You can install the App rate plugin simply as Below-

Install Plugin

Install Ionic cordova app rate plugin Example:

$ ionic plugin add --save cordova-plugin-apprate
$ npm install --save @ionic-native/app-rate

Supported Platforms

This plugin is supported in the following platforms –

  • 1. Android
  • 2. IOS
  • 3. Windows

App Rate Example

Here is simple example of app rate plugin in Ionic-

Install Ionic cordova app rate plugin Example:

import { AppRate } from '@ionic-native/app-rate';

constructor(private appRate: AppRate) { }

...

 this.appRate.preferences.storeAppURL = {
   ios: '',
   android: 'market://details?id=',
   windows: 'ms-windows-store://review/?ProductId='
 };

this.appRate.promptForRating(false);

For Ios app id is required, for Android package name and for windows product Id(Store Id) is required.

Instance Members

App Rate Preferences

td>useLanguage(optional)td>displayAppName(optional)td>promptAgainForEachNewVersion(optional)td>usesUntilPrompt(optional)td>openStoreInApp(optional)td>useCustomRateDialog(optional)td>customLocale(optional)td>callbacks(optional)td>storeAppURL(optional)
Param Type Details
string Custom BCP 47 language tag
string Custom application title
boolean Show dialog again when application version will be updated. Defaults to true
number count of runs of application before dialog will be displayed. Defaults to 3
boolean leave app or no when application page opened in app store (now supported only for iOS). Defaults to false
boolean use custom view for rate dialog. Defaults to false
any Custom locale object
AppRateCallbacks Callbacks for events
AppUrls App Store URLS

App Urls

td>ios(optional)td>android(optional)td>windows(optional)td>blackberry(optional)td>windows8(optional)
Param Type Details
string application id in AppStore
string application url in Google Play Store
string application id in Window Store
string application id in App World
string application id in Window Store

AppRateCallbacks

td>onButtonClickedtd>onRateDialogShow
Param Type Details
Function This function is called when user clicks on the rate button.
Function This function is called when rate dialog is shown.

Ionic App Preferences


Ionic App Preferences plugin– Ionic App Preferences plugin allows us to read and write app preferences. Here in this tutorial we are going to explain to import this plugin and use it.


Ionic App Preferences Plugin Example

You can install App Preferences Plugin simply as below-

Ionic App Preferences Plugin Install:

$ ionic plugin add --save cordova-plugin-app-preferences
$ npm install --save @ionic-native/app-preferences

Supported Platforms

Following Platforms are supported in app preferences –

  • Android
  • BlackBerry 10
  • Browser
  • iOS
  • OS X
  • Windows 8
  • Windows Phone

Example

First Import AppPreferences from ionic native before using it, Here is simple example-

Ionic App Preferences Plugin Example:

import { AppPreferences } from '@ionic-native/app-preferences';

constructor(private appPreferences: AppPreferences) {

  this.appPreferences.fetch('key').then((res) => { console.log(res); });

}

Instance Members

Following Instance Members are available-

  • fetch
  • store
  • remove
  • clearAll
  • show
  • watch
  • suite
  • iosSuite
  • cloudSync
  • defaults

Now let us go one by one to understand the details-

fetch(dict, key)

This method returns the preference value-

Param Type Details
dict string Dictionary For Key(optional)
Key String Key

Returns- Returns Promise any.

store(dict, key, value)

This method sets the preference value-

Param Type Details
dict string Dictionary For Key(optional)
Key String Key
Value String Value

Returns- Returns Promise any.

remove(dict, key)

This method removes the value from the preference-

Param Type Details
dict string Dictionary For Key(optional)
Key String Key

Returns- Returns Promise any.

clearAll()

This method clears the preferences-

Returns- Returns Promise any.

show()

This method shows the native preference interface-

Returns- Returns Promise any.

watch(subscribe)

This method shows the native preference interface-

subscribe(boolean)-True value to subscribe, false – unsubscribe

Returns- Returns Observable.

suite(suiteName)

Supported Platform– Android

This method shows the native preference interface-

suitName(boolean)-Return named configuration context In iOS you’ll get a suite configuration, on Android β€” named file Supports: Android, iOS.

Returns- Returns Custom Object.

isSuite()

Supported Platform– IOS

cloudSync()

Supported Platform– IOS, Windows, Windows Phone 8

Returns cloud synchronized configuration.

defaults()

Supported Platform– IOS, Windows, Windows Phone 8

Returns default configuration.