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:

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

{
"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.
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.
Most helpful comment
Solved by waiting for platform ready: