# @awesome-cordova-plugins/core 中文文档

规范地址：https://npmcn.com/package/%40awesome-cordova-plugins/core/

版本：9\.7\.0
npm 元数据更新时间：2026-10-20T12:57:18.972Z
中文译文更新时间：2026-11-07T08:54:14.864Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40awesome-cordova-plugins/core
原文对照：https://npmcn.com/package/%40awesome-cordova-plugins/core/?lang=original
项目主页：https://awesome-cordova-plugins.com/
源码仓库：https://github.com/danielsogl/awesome-cordova-plugins

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：82.2 kB，33 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：rxjs ^5\.5\.0 \|\| ^6\.5\.0 \|\| ^7\.3\.0
- 首次发布：2021-09-27T15:42:06.792Z
- 最新版本发布：2026-10-20T12:57:18.605Z
- 近 30 天下载量：497840（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：55（近 12 个月 12 个）

## 中文简介

真棒 Cordova 插件 - ionic apps 的原生插件

## 安装

```sh
npm install @awesome-cordova-plugins/core
```

也可以使用：`pnpm add @awesome-cordova-plugins/core`、`yarn add @awesome-cordova-plugins/core`、`bun add @awesome-cordova-plugins/core`

## README

![](https://img.shields.io/npm/v/@awesome-cordova-plugins/core.svg)

# 伟大的 Cordova 插件

真棒 Cordova 插件 是一个 Cordova 插件的包装套件, 它使您需要的本地功能添加到您的 [无线](https://ionicframework.com/) 移动应用程序简单.

真棒 Cordova 插件将插件的回调包在一个“承诺”或“可观察”中,为所有插件提供一个共同的界面,并方便使用带有角变化检测的插件.

要了解更多Ionic原住民 改名为 Super Cordova 插件的原因,请阅读官方网站 [音响博客](https://ionicframework.com/blog/a-new-chapter-for-ionic-native/) 由Max Lyncht撰写.

## 电容支持

除了Cordova之外,Super Cordova插件也与 [电容](https://capacitorjs.com/)Ionic官方的本土运行时间 下面的基本用途。 完整的细节, [见电容文档](https://capacitorjs.com/docs/v2/cordova/using-cordova-plugins)。 。 。 .

## 安装

按照命令运行, 在您的工程中安装 Super Cordova 插件 .

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

您还需要为您要添加的每个插件安装 Cardova 插件包 。 请看 [真棒 Cordova 插件文档](https://ionicframework.com/docs/native/) 对于如何添加和使用插件的完整指令.

## 文档

请访问所有 Cordova 插件 [https://ionicframework.com/docs/native/ 互联网档案馆的存檔,存档日期2013-12-21](https://ionicframework.com/docs/native/)。 。 。 .

### 基本用途

#### Ionic/Angular apps (单机)

Angular v14+默认使用独立的组件. 要使用插件, 请在您的应用程序拖带中注册为提供者, 并使用 Angular 输入 `inject()` 函数. 确保从 `/ngx` 以下示例所示目录:

```typescript
// 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],
});
```

```typescript
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 App必须使用Capacitor来构建本土移动应用. 然而,Super Cordova插件(并因此被Cordova插件)仍然可以被使用.

```bash
# 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
```

导入插件对象后使用其静态方法 :

```typescript
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 (不含Angular) (中文(简体) )

这些模块也可以不使用Angular,直接调用静态方法:

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

### 模拟和浏览器开发(仅Ionic/Angular apps)

惊人的 Cordova 插件可以模拟插件, 并在浏览器或浏览器中开发几乎完整的应用程序 `ionic serve`。 。 。 .

要做到这一点,您需要提供您想要使用的插件的模拟执行 。 这里有一个嘲弄 `Camera` 开发时返回库存图像的插件 :

首先创建一个模拟类,扩展 `Camera` 类 :

```typescript
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');
    });
  }
}
```

然后覆盖 `Camera` 应用程序拖网中的提供者 :

```typescript
// 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 }],
});
```

### 运行时间诊断

花了太长的时间诊断一个问题 只意识到一个插件没有发射或安装? 伟大的克多瓦 插件可以让你知道问题所在,以及如何解决问题.

![img](https://ionic-io-assets.s3.amazonaws.com/ionic-native-console.png)

## 插件丢失吗 ?

告诉我们或者提交公关! 看看这个 [开发者指南](https://github.com/danielsogl/awesome-cordova-plugins/blob/main/DEVELOPER.md) 更多关于如何贡献。 :心脏 :

# 贷项

伊比・哈迪德.. [{\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你应该知道](https://github.com/ihadeed)

丹尼尔・索格 [链接](https://www.linkedin.com/in/daniel-sogl)

蒂姆・兰西娜 [@timlancina (英语)](https://twitter.com/timlancina)

迈克・哈廷顿 [@mhartington (英语)](https://twitter.com/mhartington)

马克思·林奇 - [@ maxlynch (英语)](https://twitter.com/maxlynch)

罗布·沃默德 [@ robdrobtromard (英语)](https://twitter.com/robwormald)

## 常见问题

### @awesome-cordova-plugins/core 是什么？

真棒 Cordova 插件 - 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 和提交记录判断。

