@awesome-cordova-plugins/core

中文文档
9.7.0发布于 2026/10/20MITTypeScriptES Module构建来源已验证近 30 天下载 49.8万

Awesome Cordova Plugins - Native plugins for ionic apps

原始使用文档
文档目录7 节
  1. Capacitor Support
  2. Installation
  3. Documentation
  4. Basic Usage
  5. Mocking and Browser Development (Ionic/Angular apps only)
  6. Runtime Diagnostics
  7. Plugin Missing?

Awesome Cordova Plugins

Awesome Cordova Plugins is a curated set of wrappers for Cordova plugins that make adding any native functionality you need to your Ionic mobile app easy.

Awesome Cordova Plugins wraps plugin callbacks in a Promise or Observable, providing a common interface for all plugins and making it easy to use plugins with Angular change detection.

To learn more about the reasons why Ionic Native was renamed to Awesome Cordova Plugins, read the official Ionic blog post by Max Lyncht.

Capacitor Support

In addition to Cordova, Awesome Cordova Plugins also works with Capacitor, Ionic's official native runtime. Basic usage below. For complete details, see the Capacitor documentation.

Installation

Run following command to install Awesome Cordova Plugins in your project.

npm install @awesome-cordova-plugins/core --save

You also need to install the Awesome Cordova Plugins package for each plugin you want to add. Please see the Awesome Cordova Plugins documentation for complete instructions on how to add and use the plugins.

Documentation

For the full Awesome Cordova Plugins documentation, please visit https://ionicframework.com/docs/native/.

Basic Usage

Ionic/Angular apps (Standalone)

Angular v14+ uses standalone components by default. To use a plugin, register it as a provider in your application bootstrap and inject it using Angular's inject() function. Make sure to import the injectable class from the /ngx directory as shown in the following examples:

// main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { Camera } from '@awesome-cordova-plugins/camera/ngx';
import { Geolocation } from '@awesome-cordova-plugins/geolocation/ngx';
import { AppComponent } from './app/app.component';

bootstrapApplication(AppComponent, {
  providers: [Camera, Geolocation],
});
import { Component, OnInit } from '@angular/core';
import { inject } from '@angular/core';
import { Geolocation } from '@awesome-cordova-plugins/geolocation/ngx';
import { Platform } from '@ionic/angular';

@Component({
  selector: 'app-my-component',
  standalone: true,
  template: `<p>My Component</p>`,
})
export class MyComponent implements OnInit {
  private geolocation = inject(Geolocation);
  private platform = inject(Platform);

  async ngOnInit() {
    await this.platform.ready();

    // get position
    const pos = await this.geolocation.getCurrentPosition();
    console.log(`lat: ${pos.coords.latitude}, lon: ${pos.coords.longitude}`);

    // watch position
    const watch = this.geolocation.watchPosition().subscribe((pos) => {
      console.log(`lat: ${pos.coords.latitude}, lon: ${pos.coords.longitude}`);
    });

    // to stop watching
    watch.unsubscribe();
  }
}

Ionic/React apps

React apps must use Capacitor to build native mobile apps. However, Awesome Cordova Plugins (and therefore, Cordova plugins) can still be used.

# Install Core library (once per project)
npm install @awesome-cordova-plugins/core

# Install Awesome Cordova Plugins TypeScript wrapper
npm install @awesome-cordova-plugins/barcode-scanner

# Install Cordova plugin
npm install phonegap-plugin-barcodescanner

# Update native platform project(s) to include newly added plugin
ionic cap sync

Import the plugin object then use its static methods:

import { BarcodeScanner } from '@awesome-cordova-plugins/barcode-scanner';

const Tab1: React.FC = () => {
  const openScanner = async () => {
    const data = await BarcodeScanner.scan();
    console.log(`Barcode data: ${data.text}`);
  };
  return (
    <IonPage>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Tab 1</IonTitle>
        </IonToolbar>
      </IonHeader>
      <IonContent>
        <IonButton onClick={openScanner}>Scan barcode</IonButton>
      </IonContent>
    </IonPage>
  );
};

ES2015+/TypeScript (without Angular)

These modules can also be used without Angular by calling static methods directly:

import { Camera } from '@awesome-cordova-plugins/camera';

document.addEventListener('deviceready', () => {
  Camera.getPicture()
    .then((data) => console.log('Took a picture!', data))
    .catch((e) => console.log('Error occurred while taking a picture', e));
});

Mocking and Browser Development (Ionic/Angular apps only)

Awesome Cordova Plugins makes it possible to mock plugins and develop nearly the entirety of your app in the browser or in ionic serve.

To do this, you need to provide a mock implementation of the plugins you wish to use. Here's an example of mocking the Camera plugin to return a stock image while in development:

First create a mock class that extends the Camera class:

import { Camera } from '@awesome-cordova-plugins/camera/ngx';

class CameraMock extends Camera {
  getPicture(options) {
    return new Promise((resolve, reject) => {
      resolve('BASE_64_ENCODED_DATA_GOES_HERE');
    });
  }
}

Then override the Camera provider in your application bootstrap:

// main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { Camera } from '@awesome-cordova-plugins/camera/ngx';
import { AppComponent } from './app/app.component';

class CameraMock extends Camera {
  getPicture(options) {
    return Promise.resolve('BASE_64_ENCODED_DATA_GOES_HERE');
  }
}

bootstrapApplication(AppComponent, {
  providers: [{ provide: Camera, useClass: CameraMock }],
});

Runtime Diagnostics

Spent way too long diagnosing an issue only to realize a plugin wasn't firing or installed? Awesome Cordova Plugins lets you know what the issue is and how you can resolve it.

img

Plugin Missing?

Let us know or submit a PR! Take a look at the Developer Guide for more on how to contribute. :heart:

Credits

Ibby Hadeed - @ihadeed

Daniel Sogl - LinkedIn

Tim Lancina - @timlancina

Mike Hartington - @mhartington

Max Lynch - @maxlynch

Rob Wormald - @robwormald

版本与发布记录

@awesome-cordova-plugins/core 共发布 55 个版本,首次发布于 2021/09/27;过去 12 个月发布了 12 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
9.7.0latest2026/10/2018 天前
9.6.02026/09/082 个月前
9.5.02026/08/112 个月前
9.4.02026/07/283 个月前
9.3.02026/07/283 个月前
9.2.02026/05/115 个月前

其他发布通道:alpha → 6.0.0-alpha.4。

关于 @awesome-cordova-plugins/core 的常见问题

@awesome-cordova-plugins/core 是什么?

Awesome Cordova Plugins - Native plugins for ionic apps

如何安装 @awesome-cordova-plugins/core?

在项目目录运行 npm install @awesome-cordova-plugins/core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:rxjs(^5.5.0 || ^6.5.0 || ^7.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@awesome-cordova-plugins/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@awesome-cordova-plugins/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@awesome-cordova-plugins/core 可以商用吗?

@awesome-cordova-plugins/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@awesome-cordova-plugins/core 的下载量有多少?

根据 npm 官方下载统计,@awesome-cordova-plugins/core 在 2026/10/07 – 2026/11/05 这 30 天内被下载 497,840 次,日均约 16,595 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@awesome-cordova-plugins/core 还在维护吗?

最新版本 9.7.0 发布于 2026/10/20(18 天前);至今共发布 55 个版本,其中过去 12 个月发布了 12 个;首次发布于 2021/09/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。