Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ionic 2 App Preferences gives Plugin Not Installed #1299

Closed
danielflippance opened this issue Mar 29, 2017 · 7 comments
Closed

Ionic 2 App Preferences gives Plugin Not Installed #1299

danielflippance opened this issue Mar 29, 2017 · 7 comments

Comments

@danielflippance
Copy link

danielflippance commented Mar 29, 2017

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 #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.

@danielflippance
Copy link
Author

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 });

@danielflippance
Copy link
Author

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

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

@ihadeed
Copy link
Collaborator

ihadeed commented Mar 30, 2017

.fetch() returns a promise now.

@danielflippance
Copy link
Author

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"

@danielflippance
Copy link
Author

Solved by waiting for platform ready:

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

@loertle
Copy link

loertle commented Jan 10, 2018

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

@BinaryBlock
Copy link

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

This worked for me!!! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants