Ionic-native: Ionic 2 App Preferences gives Plugin Not Installed

Created on 29 Mar 2017  路  7Comments  路  Source: ionic-team/ionic-native

I'm using Ionic 2 and have installed the AppPreferences plugin and it's prerequisites as per the docs. When calling fetch I receive a "plugin not installed" error similar to this issue with Ionic 1 https://github.com/driftyco/ionic-native/issues/438.

Here's how I installed:

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

Fetch the preferences:

import { AppPreferences } from '@ionic-native/app-preferences';
constructor(
  private appPreferences: AppPreferences,
...
let fetchRes = this.appPreferences.fetch('mysetting');
console.log('++ fetchRes: ' + JSON.stringify(fetchRes));

Returns:

{"error":"plugin_not_installed"}

Calling with a promise returns ".then is not a function":

    this.appPreferences.fetch('mysetting').then(function(res) {

The plugin is listed in package.json:

"dependencies": {
  ...
  "@ionic-native/app-preferences": "^3.4.2",
...
"cordovaPlugins": [
  "cordova-plugin-app-preferences",

And config.xml

<plugin name="cordova-plugin-inappbrowser" spec="~1.7.0"/>

I've included it in app.module.ts

import { AppPreferences } from '@ionic-native/app-preferences';
@NgModule({
...
providers: [
  AppPreferences,

It shows up under /node_modules:

screen shot 2017-03-29 at 11 35 40 am

{
  "name": "@ionic-native/app-preferences",
  "version": "3.4.2",

and /plugins:

screen shot 2017-03-29 at 11 35 52 am

{
  "name": "cordova-plugin-app-preferences",
  "version": "0.99.3",

The header of my index.html looks like this:

<head>
  <meta charset="UTF-8">
  <title>Ionic App</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">

  <link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
  <link rel="manifest" href="manifest.json">
  <meta name="theme-color" content="#4e8ef7">

  <!-- cordova.js required for cordova apps -->
  <script src="cordova.js"></script>

  <!-- un-comment this code to enable service worker
  <script>
    if ('serviceWorker' in navigator) {
      navigator.serviceWorker.register('service-worker.js')
        .then(() => console.log('service worker installed'))
        .catch(err => console.log('Error', err));
    }
  </script>-->

  <link href="build/main.css" rel="stylesheet">

</head>

There is no reference to any of the @ionic-native plugins here but the others seem to work fine: eg: inappbrowser, so I suppose that is not needed for Ionic 2.

Most helpful comment

Solved by waiting for platform ready:

platform.ready().then(() => { .this.appPreferences.fetch().then()... }

All 7 comments

Strangely I notice that .store does work with no error, and the promise is returned correctly:

this.appPreferences.store('mysetting', 'thenewvalue')
.then(function(value) { //This gets successfully called });

I've installed 3.4.3 and .fetch() now returns:

{"__zone_symbol__state":false,"__zone_symbol__value":"plugin_not_installed"}

.fetch() returns a promise now.

Thanks. I'm now seeing an error when .then() is called:

this.appPreferences.fetch('mysetting').then(function(res) {
  alert('++ Fetch succeeded res: ' + JSON.stringify(res)); 
}, function(err) {
  alert('++ Fetch err: ' + JSON.stringify(err));
});

Outputs:

++ Fetch err: "plugin_not_installed"

Solved by waiting for platform ready:

platform.ready().then(() => { .this.appPreferences.fetch().then()... }

For browser try: first "ionic cordova build browser" and after that "ionic cordova run browser".
Helped me.

For browser try: first "ionic cordova build browser" and after that "ionic cordova run browser".
Helped me.

This worked for me!!! Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wwallace picture wwallace  路  4Comments

Manduro picture Manduro  路  3Comments

kyleap picture kyleap  路  4Comments

rajanshahsa picture rajanshahsa  路  3Comments

JaneDawson picture JaneDawson  路  4Comments