Guide
How to use Bluetooth Low Energy in Capacitor
@capgo/capacitor-블루투스-저전력-에너지 사용
Capacitor 블루투스 저전력 에너지 플러그인 BLE 통신을위한
설치
bun add @capgo/capacitor-bluetooth-low-energy
bunx cap sync
bunx cap sync code의 네이티브 코드를 프로젝트에 복사합니다. 플러그인 업그레이드 후 다시 실행하세요.
수입
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
API의 개요
| 방법 | 설명 |
|---|---|
initialize |
BLE 플러그인을 초기화합니다. 다른 메서드를 호출하기 전에 반드시 호출해야 합니다. |
shimWebBluetooth |
Capacitor Web Bluetooth shim을 Capacitor에 설치하세요. navigator.bluetoothCapacitor 네이티브 앱에서 Web Bluetooth API를 사용하기 전에 이 메서드를 수동으로 호출하세요. |
isAvailable |
장치에 블루투스가 사용 가능한지 확인합니다. |
isEnabled |
장치에 블루투스가 활성화되어 있는지 확인합니다. |
isLocationEnabled |
장치에 위치 서비스가 활성화되어 있는지 확인합니다. (안드로이드 전용) |
openAppSettings |
앱 설정 페이지를 열어주세요. |
openBluetoothSettings |
블루투스 설정 페이지를 열어주세요. (안드로이드 전용) |
openLocationSettings |
위치 설정 페이지를 열어주세요. (안드로이드 전용) |
checkPermissions |
현재 권한 상태를 확인합니다. |
requestPermissions |
블루투스 권한을 요청합니다. |
startScan |
BLE 장치 검색 시작. |
stopScan |
BLE 장치 검색 중지. |
connect |
BLE 장치에 연결. |
disconnect |
BLE 장치에서 연결 해제. |
createBond |
BLE 장치와 결합 (안드로이드 전용). |
isBonded |
BLE 장치가 결합되었는지 확인 (안드로이드 전용). |
discoverServices |
연결된 장치의 서비스 발견. |
getServices |
장치의 발견된 서비스 가져오기. |
getConnectedDevices |
연결된 장치 목록 가져오기. |
readCharacteristic |
특성 값 읽기. |
writeCharacteristic |
특성 값에 쓰기. |
startCharacteristicNotifications |
특성에 알림 시작. |
stopCharacteristicNotifications |
BLE 특성에 대한 알림을 중지합니다. |
readDescriptor |
특성의 디스크립터 값을 읽습니다. |
writeDescriptor |
디스크립터에 값을 씁니다. |
readRssi |
연결된 장치의 RSSI(신호 강도)를 읽습니다. |
requestMtu |
MTU 크기 변경을 요청합니다. (Android 전용). |
requestConnectionPriority |
연결 우선순위를 요청합니다. (Android 전용). |
startAdvertising |
BLE 서버로 광고를 시작합니다. |
stopAdvertising |
광고를 중지합니다. |
addGattService |
GATT 서비스와 특성을 GATT 서버에 추가합니다. 주소는 주변 모드에서 광고를 시작하기 전에 호출해야 합니다. |
removeGattService |
GATT 서버에서 GATT 서비스를 제거합니다. |
setGattCharacteristicValue |
GATT 특성의 값을 설정합니다. |
notifyGattCharacteristicChanged |
연결된 센트럴에게 GATT 특성의 값이 변경되었음을 알립니다. |
startForegroundService |
백그라운드에서 BLE 연결을 유지하기 위해 Android에서만 사용할 수 있는 전면 서비스를 시작합니다. |
stopForegroundService |
Android에서만 사용할 수 있는 전면 서비스를 중지합니다. |
예시
initialize()
블루투스低에너지 플러그인을 초기화합니다. 다른 메서드를 호출하기 전에 반드시 호출해야 합니다.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.initialize({ mode: 'central' });
shimWebBluetooth()
Capacitor 웹 블루투스 시뮬레이터를 설치하세요 navigator.bluetooth웹 블루투스 API를 사용하기 전에, Capacitor 네이티브 앱에서 이 함수를 수동으로 호출하세요.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
BluetoothLowEnergy.shimWebBluetooth();
isAvailable()
장치에 블루투스가 활성화되어 있는지 확인합니다.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { available } = await BluetoothLowEnergy.isAvailable();
isEnabled()
Android에서만 사용할 수 있는 위치 서비스가 활성화되어 있는지 확인합니다.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isEnabled();
isLocationEnabled()
앱 설정 페이지를 열어줍니다.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
const { enabled } = await BluetoothLowEnergy.isLocationEnabled();
openAppSettings()
위 표에는 36개의 핵심 메서드가 나열되어 있습니다. 리스너 및 버전 헬퍼, 각 메서드의 전체 계약은 __CAPGO_KEEP_0__ 저장소에서 문서화되어 있습니다.
import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';
await BluetoothLowEnergy.openAppSettings();
__CAPGO_KEEP_0__ 저장소에서 문서화되어 있습니다. GitHub 저장소에서 문서화되어 있습니다..
이벤트를 듣다
addListener 핸들을 반환합니다. 화면이 언마운트되거나 handle.remove() 모든 리스너를 지우려면 BluetoothLowEnergy.removeAllListeners() 전체 참조
__CAPGO_KEEP_0__ 저장소
capgo/capacitor-블루투스-저전력-을 사용 중이라면
__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-블루투스-저전력-을 사용하여 @capgo/capacitor-블루투스 저전력 에너지 __CAPGO_KEEP_0__/__CAPGO_KEEP_1__-블루투스-저전력-을 연결하세요 @capgo/capacitor-블루투스 저전력 @capgo/capacitor 블루투스 저전력 에너지 시작하기 Capacitor-블루투스 저전력에 대한 구현 세부 정보 Capgo 플러그인 디렉토리 for the product workflow in Capgo Plugin Directory, Capacitor Capgo 플러그인 for Capacitor 구현 세부사항에 대한 Capgo 플러그인에 의해 플러그인 추가 또는 업데이트 Capacitor-블루투스 저전력에 대한 구현 세부 정보