コンテンツにスキップ

始め方

GitHub

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

Terminal window
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Then use the following prompt:

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

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

Terminal window
bun add @capgo/capacitor-device-info
bunx cap sync
import { DeviceInfo } from '@capgo/capacitor-device-info';

1つのスナップショットを読みます

セクション: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使用率が充填された場合に再度呼び出すか、監視を使用して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);
});
await DeviceInfo.startMonitoring({
intervalMs: 1000,
emitImmediately: true,
});

セクション:ストリームの更新を停止

コピーする
await DeviceInfo.stopMonitoring();
await handle.remove();

自動停止も可能です:

await DeviceInfo.startMonitoring({
intervalMs: 1000,
durationMs: 60_000,
sampleCount: 60,
});
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サポートはベストエフォートであり、ブラウザがnativeデバイスセンサを一貫して公開していないため、オンボードセンサ配列を空に報告します。
export interface DeviceInfoSnapshot {
timestamp: number;
platform: 'ios' | 'android' | 'web';
cpu: CpuInfo;
memory: MemoryInfo;
storage: StorageInfo;
gpu?: GpuInfo;
thermalState?: ThermalState;
lowPowerMode?: boolean;
sensors?: OnboardSensorsInfo;
}
export interface OnboardSensorsInfo {
availableSensors?: OnboardSensorDescriptor[];
readings?: OnboardSensorReading[];
batteryTemperatureCelsius?: number;
ambientTemperatureCelsius?: number;
relativeHumidityPercent?: number;
pressureHpa?: number;
illuminanceLux?: number;
proximityDistanceCm?: number;
}
export interface MonitoringOptions {
intervalMs?: number;
durationMs?: number;
sampleCount?: number;
emitImmediately?: boolean;
}

このページはプラグインから生成されています。 src/definitions.tspublic API の変更をアップストリームで再実行してください。

Getting Started から続けてください

Getting Started から続けてください

Capgo を使用している場合 Capgo を使用している場合、デバイス診断用に接続してください。 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-device-info @capgo/capacitor-device-info を使用して概要を確認してください。 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-barometer @capgo/capacitor-barometer を使用してチュートリアルを実行してください。 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-barometer @capgo/capacitor-barometer for focused pressure readings, and @capgo/capacitor-light-sensor for focused light sensor readings。