首页 > 解决方案 > Ionic 3 - Native AppPrefences plugin_not_installed 错误

问题描述

这让我发疯了。所以我为此创建了一个专门的项目,这就是我所做的。

创建空白离子项目。这是控制台输出

[DEBUG] Reason for not using local CLI: BASE_DIRECTORY_NOT_FOUND
[DEBUG] CLI flags: { interactive: true, confirm: false }
[DEBUG] { cwd: 'E:\\Project\\Ionic', local: false, binPath:
        'C:\\Users\\yandi\\AppData\\Roaming\\npm\\node_modules\\ionic\\bin\\ionic', libPath:
        'C:\\Users\\yandi\\AppData\\Roaming\\npm\\node_modules\\ionic\\dist\\index.js' }
[DEBUG] Daemon found (pid: 11712)

? What starter would you like to use: blank
√ Creating directory .\AppPreferences - done!
√ Downloading and extracting blank starter - done!

? Would you like to integrate your new app with Cordova to target native iOS and Android? Yes
√ Personalizing ionic.config.json and package.json - done!
> ionic integrations enable cordova --quiet
√ Downloading integration cordova - done!
[DEBUG] Integration files downloaded to C:\Users\yandi\AppData\Local\Temp\ionic-integration-cordova (files: config.xml,
        resources)
[DEBUG] Blacklist:
√ Copying integrations files to project - done!
[OK] Added cordova integration!

Installing dependencies may take several minutes.

> npm i
√ Running command - done!

获取所需的 Cordova 插件。控制台输出

√ Creating .\www directory for you - done!
> cordova plugin add cordova-plugin-app-preferences --save
Adding cordova-plugin-app-preferences to package.json

Saved plugin info for "cordova-plugin-app-preferences" to config.xml

获取所需的 npm 包。控制台输出

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @ionic-native/app-preferences@4.7.0
added 1 package in 26.305s

将插件添加到我的 app.module

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

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

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    AppPreferences,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

然后这是我的 page.ts

import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';

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

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, public appPreferences: AppPreferences, public platform: Platform) {}

  checkPref(){
    this.platform.ready().then((success) => {
      this.appPreferences.show().then((success) => {
        alert(success);
      }, (fail) => {
        alert(fail);
      });
    }, (fails) => {
      console.log(fails);
    });
  }

}

page.html

<ion-content padding>
  <button ion-button (click)="checkPref()">Check Plugin</button>
</ion-content>

当我点击它时,它显示“plugin_not_installed”

那么,我做错了什么?真的让我很沮丧。我已经弄清楚了我的应用程序上的所有内容,这是我需要的最后一点

**更新:我在 Ionic Dev App 的帮助下在我的手机(小米米 4i)上提供它

标签: javascriptionic-frameworkionic3ionic-native

解决方案


cordova-plugin-app-preferences不支持Ionic DevApp

因此,您需要将其构建为 apk 并作为真正的应用程序运行。

有关受支持插件的完整列表,请参阅Ionic DevApp 文档


推荐阅读