본문 바로가기

시작하기

GitHub

AI-Assisted Setup으로 플러그인을 설치할 수 있습니다. 다음 명령어로 AI 도구에 Capgo 스킬을 추가하세요:

터미널 창
bunx 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-light-sensor` plugin in my project.

수동 설정을 선호한다면, 다음 명령어를 실행하여 플러그인을 설치하고 아래의 플랫폼별 지침을 따르세요:

터미널 창
bun add @capgo/capacitor-light-sensor
bunx cap sync
import { LightSensor } from '@capgo/capacitor-light-sensor';
import { LightSensor } from '@capgo/capacitor-light-sensor';
const { available } = await LightSensor.isAvailable();
import { LightSensor } from '@capgo/capacitor-light-sensor';
await LightSensor.start({ updateInterval: 500 });
import { LightSensor } from '@capgo/capacitor-light-sensor';
await LightSensor.stop();

자주 하는 실수

“흔한 실수” 섹션
  • 권한: 호출 checkPermissions() 그다음 requestPermissions() 필요할 때.
  • 리스너: 화면이 언마운트될 때 핸들을 제거합니다.
  • 신뢰할 수 있는 소스: 신뢰 src/definitions.ts GitHub 레포지토리에서.

현재 기기에서 조도 센서를 사용할 수 있는지 확인하세요. 센서를 사용하기 전에 항상 사용 가능 여부를 먼저 확인해야 합니다.

import { LightSensor } from '@capgo/capacitor-light-sensor';
const { available } = await LightSensor.isAvailable();

조도 센서 업데이트를 수신합니다. 지정한 간격으로 센서 측정이 시작됩니다. 센서 데이터를 받으려면 addListener 를 사용하세요.

import { LightSensor } from '@capgo/capacitor-light-sensor';
await LightSensor.start({ updateInterval: 500 });

조도 센서 업데이트 수신을 중단합니다. 센서 작동을 멈추고 배터리를 절약합니다.

import { LightSensor } from '@capgo/capacitor-light-sensor';
await LightSensor.stop();

고속 샘플링 센서의 현재 권한 상태를 확인합니다. Android 12 이상에서는 센서 업데이트 간격이 200ms 미만일 경우 HIGH_SAMPLING_RATE_SENSORS 권한이 필요합니다.

import { LightSensor } from '@capgo/capacitor-light-sensor';
const status = await LightSensor.checkPermissions();

높은 샘플링 속도 센서 사용 권한을 요청합니다. Android 12 이상에서는 HIGH_SAMPLING_RATE_SENSORS 권한을 요청합니다.

import { LightSensor } from '@capgo/capacitor-light-sensor';
const status = await LightSensor.requestPermissions();

타입 레퍼런스

“타입 참조” 섹션

센서 사용 가능 여부를 나타내는 결과값입니다.

export interface IsAvailableResult {
/**
* Whether the light sensor is available on this device.
* Always false on iOS as the light sensor API is not available.
*
* @since 0.0.1
*/
available: boolean;
}

조도 센서 리스너를 시작하기 위한 옵션입니다.

export interface StartOptions {
/**
* The desired interval between sensor updates in milliseconds.
* On Android 12+, there's a minimum interval of 200ms unless the app
* has the HIGH_SAMPLING_RATE_SENSORS permission.
*
* @default 200
* @since 0.0.1
*/
updateInterval?: number;
}

조도 센서 업데이트를 위한 콜백 함수입니다.

export type LightSensorCallback = (measurement: LightSensorMeasurement) => void;

권한 요청 또는 확인 결과입니다.

export interface PermissionStatus {
/**
* Whether the high sampling rate sensor permission is granted.
* On Android 12+, this permission is required for update intervals below 200ms.
*
* @since 0.0.1
*/
highSamplingRate: 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied';
}

플러그인 버전 정보입니다.

export interface VersionResult {
/**
* The current version of the plugin.
*
* @since 0.0.1
*/
version: string;
}

단일 조도 센서 측정값입니다.

export interface LightSensorMeasurement {
/**
* Ambient light level in lux (lx).
*
* @since 0.0.1
*/
illuminance: number;
/**
* Timestamp of the measurement in seconds since epoch.
*
* @since 0.0.1
*/
timestamp: number;
}

이 페이지는 플러그인의 src/definitions.tsupstream에서 public API가 변경되면 sync를 다시 실행하세요.

사용 중이라면 시작하기 대시보드 및 API 운영을 계획하려면, 이를 다음과 연결하세요 @capgo/capacitor-light-sensor 사용하기 @capgo/capacitor-light-sensor 사용 시 네이티브 기능을 위해, API 개요 구현 세부 사항은 API 개요에서 소개 구현 세부 사항은 소개에서 API 키 API Keys의 구현 세부 사항은, 기기 Devices의 구현 세부 사항은.