JavaScript

Getting Started

GitHub

@capgo/capacitor-device-info requires Capacitor 8 or later (@capacitor/core >=8.0.0).

CapgoのAIアシストセットアップを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを使用してください。

ターミナル画面
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

次に、以下のコマンドを使用してください:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-device-info` plugin in my project.

手動セットアップの場合、パッケージをインストールし、ネイティブプロジェクトを同期してください:

ターミナル画面
npm install @capgo/capacitor-device-info
npx cap sync
import { DeviceInfo } from '@capgo/capacitor-device-info';

「1つのスナップショットを読み取る」セクション

コマンドプロンプト
const snapshot = await DeviceInfo.getInfo();
console.log(snapshot.cpu.cores);
console.log(snapshot.memory.usedPercent);
console.log(snapshot.storage.freeBytes);
console.log(snapshot.sensors?.pressureHpa);

cpu.usagePercent Δ値ベースです。最初のネイティブサンプルでは省略できます; 2回目のサンプル後にCPU使用率が充填された場合に呼び出すことができます。 getInfo() ストリームの更新

「ストリームの更新」セクション

クリップボードにコピー
const handle = await DeviceInfo.addListener('deviceInfoUpdate', (sample) => {
console.log(sample.sequence, sample.elapsedMs);
console.log(sample.cpu.usagePercent);
console.log(sample.sensors?.readings);
});
const session = await DeviceInfo.startMonitoring({
intervalMs: 1000,
emitImmediately: true,
});
console.log(session.intervalMs, session.startedAt);

「監視の動作」セクション

デフォルト値は
  • intervalMs ミリ秒です。以下の値は 1000 ミリ秒に丸められます。 250 デフォルト値は 250.
  • emitImmediately Stream updates true.
  • 設定 durationMs または sampleCount Capacitorライブアップデートの代替品の比較ページ
  • Capacitorライブアップデートの代替品の比較ページ startMonitoring() Capawesomeの比較ページ
  • コンサルティングサービスページ deviceInfoUpdate Appflowの比較/移行マーケティングコピー sequenceAppflowの比較/移行マーケティングコピー startedAt Appflowプラグインまたは elapsedMs.
await DeviceInfo.stopMonitoring();
await handle.remove();
// Or remove every listener registered on this plugin:
await DeviceInfo.removeAllListeners();
const state = await DeviceInfo.isMonitoring();
if (state.monitoring) {
console.log(state.samplesEmitted);
}

センサーフィールドをオンボードする

「センサーフィールドをオンボードする」セクション
const { sensors, cpu, gpu } = await DeviceInfo.getInfo();
console.log(cpu.temperatureCelsius);
console.log(gpu?.temperatureCelsius);
console.log(sensors?.batteryTemperatureCelsius);
console.log(sensors?.ambientTemperatureCelsius);
console.log(sensors?.relativeHumidityPercent);
console.log(sensors?.pressureHpa);
console.log(sensors?.illuminanceLux);
console.log(sensors?.proximityDistanceCm);
console.log(sensors?.availableSensors);

センサーフィールドは任意です。デバイス、OS、そしてアプリケーションサンドボックスがそのメトリックを公開している場合にのみ表示されます。

プラットフォームに関する注意

「プラットフォームに関する注意」セクション
  • iOSでは、公開メトリックに対して許可が必要ありません。CoreMotionセンサーの可用性を報告しますが、raw CPUまたはGPU温度は報告しません。
  • Androidでは、公開メトリックに対して許可が必要ありません。CPUおよびGPU温度はベストエフォートの熱帯域読み取りです。
  • Webサポートはベストエフォートであり、ブラウザがネイティブデバイスセンサを一貫して公開していないため、空のオンボードセンサーアレイを報告します。
メソッド戻り値注記
getInfo()Promise<DeviceInfoSnapshot>1 つのスナップショットを読み取ります。
startMonitoring(options?)Promise<StartMonitoringResult>定期的なスナップショットを開始します、またはアクティブ セッションを新しいオプションで再起動します。
stopMonitoring()Promise<StopMonitoringResult>アクティブ セッションを停止します。
isMonitoring()Promise<MonitoringState>現在のセッション状態を返します。
addListener('deviceInfoUpdate', listener)Promise<PluginListenerHandle>定期的なスナップショットリスナーを登録します。
removeAllListeners()Promise<void>プラグインで登録されたすべてのリスナーを削除します。
getPluginVersion()Promise<PluginVersionResult>ネイティブ プラグインのバージョンを読み取ります。

PluginListenerHandle はCapacitorによって提供され、 remove() を削除するために使用します。

interface CpuInfo {
cores: number;
activeCores?: number;
architecture?: string;
model?: string;
usagePercent?: number | null;
maxFrequencyHz?: number;
temperatureCelsius?: number;
}
interface MemoryInfo {
totalBytes?: number;
freeBytes?: number;
usedBytes?: number;
usedPercent?: number;
appUsedBytes?: number;
appLimitBytes?: number;
lowMemory?: boolean;
pressure?: 'normal' | 'warning' | 'critical' | 'unknown';
}
interface StorageInfo {
totalBytes?: number;
freeBytes?: number;
usedBytes?: number;
usedPercent?: number;
}
interface GpuInfo {
api?: 'metal' | 'opengl' | 'webgl' | 'unknown';
vendor?: string;
renderer?: string;
version?: string;
maxTextureSize?: number;
temperatureCelsius?: number;
}
type ThermalState = 'nominal' | 'fair' | 'serious' | 'critical' | 'unknown';
interface DeviceInfoSnapshot {
timestamp: number;
platform: 'ios' | 'android' | 'web';
cpu: CpuInfo;
memory: MemoryInfo;
storage: StorageInfo;
gpu?: GpuInfo;
thermalState?: ThermalState;
lowPowerMode?: boolean;
sensors?: OnboardSensorsInfo;
}

サイズはバイトです、 maxFrequencyHz はヘルツ、温度の値はセルシウスです。 usagePercentnull データが十分なサンプルを取得するまで

interface OnboardSensorDescriptor {
type: string;
name?: string;
vendor?: string;
platformType?: number;
maximumRange?: number;
resolution?: number;
powerMilliamp?: number;
minDelayMicroseconds?: number;
wakeUp?: boolean;
}
interface OnboardSensorReading {
type: string;
unit: string;
value: number;
name?: string;
timestamp?: number;
}
interface OnboardSensorsInfo {
availableSensors?: OnboardSensorDescriptor[];
readings?: OnboardSensorReading[];
batteryTemperatureCelsius?: number;
ambientTemperatureCelsius?: number;
relativeHumidityPercent?: number;
pressureHpa?: number;
illuminanceLux?: number;
proximityDistanceCm?: number;
}

Unix エポックミリ秒のタイムスタンプはセンサーの読み取りです。一般的な単位は、セルシウス、パーセント、hPa、ルックス、センチメートルです。

interface MonitoringOptions {
intervalMs?: number;
durationMs?: number;
sampleCount?: number;
emitImmediately?: boolean;
}
interface StartMonitoringResult {
monitoring: boolean;
intervalMs: number;
startedAt: number;
}
interface StopMonitoringResult {
monitoring: boolean;
}
interface MonitoringState {
monitoring: boolean;
intervalMs?: number;
startedAt?: number;
samplesEmitted?: number;
}
interface DeviceInfoUpdate extends DeviceInfoSnapshot {
sequence: number;
startedAt: number;
elapsedMs: number;
}
interface PluginVersionResult {
version: string;
}

startedAt, timestampelapsedMs ミリ秒です。 sequence 開始 1 各監視セッション

This reference follows the public API in the plugin’s src/definitions.tsのパブリック__CAPGO_KEEP_0__を追跡しています。 このページを更新してください、そのソースが変更されたときに。

Capacitorを使用している場合 Capacitor デバイス診断用にCapacitorを使用している場合、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-device-infoに接続してください デバイスの概要については、@capgo/capacitor-device-infoを参照してください Capacitorのチュートリアルページについては、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-device-infoを参照してください 圧力値を取得するには、@capgo/capacitor-barometerを使用してください 焦点圧力値を取得するには、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-barometerを使用してください 明るさを取得するには、@capgo/capacitor-light-sensorを使用してください 続けて始めましょう @capgo/capacitor-light-sensor __CAPGO_KEEP_0__