@capacitor-community/device

中文文档
8.0.0发布于 2026/02/09MITTypeScriptESM + CJS零依赖近 30 天下载 3.4万

This plugin offers the API which has been removed from @capacitor/device plugin in v7.0 (getInfo() no longer returns diskFree, diskTotal, realDiskFree and realDiskTotal)

原始使用文档
文档目录12 节
  1. Capacitor Device Plugin
  2. Maintainers
  3. About
  4. Plugin versions
  5. Supported Platforms
  6. Installation
  7. Apple Privacy Manifest Requirements
  8. Example PrivacyInfo.xcprivacy
  9. Example Plugin Usage
  10. API
  11. getInfo()
  12. Interfaces


Capacitor Device Plugin

@capacitor-community/device

Capacitor community plugin to obtain internal information about the device (e.g. disk space, etc.)


Table of Contents

Maintainers

MaintainerGitHubActive
ryaaryaayes

About

This plugin offers the API which has been removed from @capacitor/device plugin in v7.0 (getInfo() no longer returns diskFree, diskTotal, realDiskFree and realDiskTotal). For more details also see https://capacitorjs.com/docs/updating/7-0#device

This plugin contains code derived from or inspired by @capacitor/device plugin. Please note that it is a community plugin, not maintained by the Capacitor team.

Features:

  • support reading diskFree, diskTotal, realDiskFree and realDiskTotal

NOTE: The plugin version 8.0.0 is compatible with Capacitor 8

Plugin versions

Capacitor versionPlugin version
8.x8.x
7.x7.x

Supported Platforms

  • iOS
  • Android

Installation

npm install @capacitor-community/device
npx cap sync

Apple Privacy Manifest Requirements

Apple mandates that app developers now specify approved reasons for API usage to enhance user privacy. By May 1st, 2024, it's required to include these reasons when submitting apps to the App Store Connect.

When using this specific plugin in your app, you must create a PrivacyInfo.xcprivacy file in /ios/App or use the VS Code Extension to generate it, specifying the usage reasons.

For detailed steps on how to do this, please see the Capacitor Docs.

For this plugin, the required dictionary key is NSPrivacyAccessedAPICategoryDiskSpace and the recommended reason is 85F4.1.

Example PrivacyInfo.xcprivacy

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>NSPrivacyAccessedAPITypes</key>
    <array>
      <!-- Add this dict entry to the array if the PrivacyInfo file already exists -->
      <dict>
        <key>NSPrivacyAccessedAPIType</key>
        <string>NSPrivacyAccessedAPICategoryDiskSpace</string>
        <key>NSPrivacyAccessedAPITypeReasons</key>
        <array>
          <string>85F4.1</string>
        </array>
      </dict>
    </array>
  </dict>
</plist>

Example Plugin Usage

import { CommunityDevice } from '@capacitor-community/device';

const logDeviceInfo = async () => {
  const info = await CommunityDevice.getInfo();

  console.log(info);
};

API

getInfo()

getInfo() => Promise<CommunityDeviceInfo>

Return information about the underlying device/os/platform.

Returns: Promise<CommunityDeviceInfo>

Since: 7.0.0


Interfaces

CommunityDeviceInfo

PropTypeDescriptionSince
diskFreenumberHow much free disk space is available on the normal data storage path for the os, in bytes. On Android it returns the free disk space on the "system" partition holding the core Android OS. On iOS this value is not accurate.7.0.0
diskTotalnumberThe total size of the normal data storage path for the OS, in bytes. On Android it returns the disk space on the "system" partition holding the core Android OS.7.0.0
realDiskFreenumberHow much free disk space is available on the normal data storage, in bytes.7.0.0
realDiskTotalnumberThe total size of the normal data storage path, in bytes.7.0.0

版本与发布记录

@capacitor-community/device 共发布 2 个版本,首次发布于 2025/05/27;过去 12 个月发布了 1 个版本。

版本发布日期距今
8.0.0latest2026/02/098 个月前
7.0.02025/05/271.5 年前

关于 @capacitor-community/device 的常见问题

@capacitor-community/device 是什么?

This plugin offers the API which has been removed from @capacitor/device plugin in v7.0 (getInfo() no longer returns diskFree, diskTotal, realDiskFree and realDiskTotal)

如何安装 @capacitor-community/device?

在项目目录运行 npm install @capacitor-community/device,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-community/device 支持 TypeScript 吗?

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

@capacitor-community/device 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-community/device 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@capacitor-community/device 可以商用吗?

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

@capacitor-community/device 的下载量有多少?

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

@capacitor-community/device 还在维护吗?

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