본문 바로가기

Bluetooth Low Energy Capacitor 플러그인

Bluetooth 기기 스캔, 연결, 읽기, 쓰기 및 알림 수신을 지원하는 풀스택 BLE 플러그인

설치

bun add @capgo/capacitor-bluetooth-low-energy bunx cap sync
npm, pnpm 또는 yarn
  • npm install @capgo/capacitor-bluetooth-low-energy
  • pnpm add @capgo/capacitor-bluetooth-low-energy
  • yarn add @capgo/capacitor-bluetooth-low-energy

가이드

Capacitor에서 Bluetooth Low Energy 사용하는 방법

@capgo/capacitor-bluetooth-low-energy 사용하기

BLE 통신을 위한 Capacitor Bluetooth Low Energy Plugin.

설치

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을 설치하세요: navigator.bluetooth. Capacitor 네이티브 앱에서 Web Bluetooth API를 사용하기 전에 이 메서드를 수동으로 호출해야 합니다.
isAvailable 기기에서 Bluetooth를 사용할 수 있는지 확인합니다.
isEnabled 기기의 Bluetooth 활성화 여부를 확인합니다.
isLocationEnabled 위치 서비스가 활성화되어 있는지 확인합니다 (Android 전용).
openAppSettings 앱 설정 페이지를 엽니다.
openBluetoothSettings Bluetooth 설정 페이지를 엽니다 (Android 전용).
openLocationSettings 위치 설정 페이지를 엽니다 (Android 전용).
checkPermissions 현재 권한 상태를 확인합니다.
requestPermissions Bluetooth 권한을 요청합니다.
startScan BLE 장치 스캔을 시작합니다.
stopScan BLE 장치 스캔을 중단합니다.
connect BLE 장치에 연결합니다.
disconnect BLE 장치 연결을 해제합니다.
createBond BLE 기기와 본딩합니다 (Android 전용).
isBonded 기기가 본딩되었는지 확인합니다 (Android 전용).
discoverServices 연결된 기기에서 서비스를 검색합니다.
getServices 기기에서 검색된 서비스 목록을 가져옵니다.
getConnectedDevices 연결된 디바이스 목록을 가져옵니다.
readCharacteristic Characteristic 값을 읽습니다.
writeCharacteristic Characteristic에 값을 씁니다.
startCharacteristicNotifications Characteristic 알림을 시작합니다.
stopCharacteristicNotifications characteristic의 알림을 중지합니다.
readDescriptor descriptor 값을 읽습니다.
writeDescriptor descriptor에 값을 씁니다.
readRssi 연결된 장치의 RSSI(신호 강도)를 읽습니다.
requestMtu MTU 크기 변경을 요청합니다 (Android 전용).
requestConnectionPriority 연결 우선순위를 요청합니다 (Android 전용).
startAdvertising Peripheral(BLE server)로 advertising을 시작합니다.
stopAdvertising Advertising을 중지합니다.
addGattService 로컬 GATT 서버에 특성(characteristic)을 포함한 GATT 서비스를 추가합니다. 광고(advertising)를 시작하기 전, peripheral 모드에서 호출해야 합니다.
removeGattService 로컬 GATT 서버에서 GATT 서비스를 제거합니다.
setGattCharacteristicValue 로컬 GATT 특성(characteristic)의 값을 설정합니다.
notifyGattCharacteristicChanged 로컬 GATT 특성 값이 변경되었음을 연결된 central 기기에 알립니다.
startForegroundService 백그라운드에서 BLE 연결을 유지하기 위해 포그라운드 서비스를 시작합니다 (Android 전용).
stopForegroundService 포그라운드 서비스를 중지합니다 (Android 전용).

예시

initialize()

BLE 플러그인을 초기화합니다. 다른 메서드를 호출하기 전에 반드시 먼저 호출해야 합니다.

import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';

await BluetoothLowEnergy.initialize({ mode: 'central' });

shimWebBluetooth()

Capacitor Web Bluetooth shim을 설치합니다. navigator.bluetoothCapacitor 네이티브 앱에서 Web Bluetooth API를 사용하기 전에 이 메서드를 수동으로 호출하세요.

import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';

BluetoothLowEnergy.shimWebBluetooth();

isAvailable()

기기에서 Bluetooth 사용이 가능한지 확인합니다.

import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';

const { available } = await BluetoothLowEnergy.isAvailable();

isEnabled()

기기의 Bluetooth 활성화 여부를 확인합니다.

import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';

const { enabled } = await BluetoothLowEnergy.isEnabled();

isLocationEnabled()

위치 서비스 활성화 여부를 확인합니다 (Android 전용).

import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';

const { enabled } = await BluetoothLowEnergy.isLocationEnabled();

openAppSettings()

앱 설정 페이지를 엽니다.

import { BluetoothLowEnergy } from '@capgo/capacitor-bluetooth-low-energy';

await BluetoothLowEnergy.openAppSettings();

위 표에는 36개의 핵심 메서드가 나열되어 있습니다. Listener와 버전 헬퍼, 각 메서드의 전체 계약은 다음 문서에서 확인할 수 있습니다. GitHub 리포지토리.

이벤트 수신

addListener 핸들을 반환합니다. 호출하세요 handle.remove() 화면이 언마운트될 때, 또는 BluetoothLowEnergy.removeAllListeners() 모든 리스너를 해제하려면.

전체 레퍼런스

@capgo/capacitor-bluetooth-low-energy 사용하기 단계에서 계속 진행하세요.

사용 중이라면 @capgo/capacitor-bluetooth-low-energy 사용하기 네이티브 플러그인 작업을 계획하려면, 이를 다음 항목과 연결하세요: @capgo/capacitor-bluetooth-low-energy @capgo/capacitor-bluetooth-low-energy의 구현 세부 사항은 다음과 같습니다. 시작하기 Getting Started의 구현 상세 내용은 Capgo 플러그인 디렉토리 Capgo Plugin Directory의 제품 워크플로우에 맞춰, Capgo의 Capacitor 플러그인 Capgo의 Capacitor Plugins 구현 세부 사항 및 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트의 구현 세부 사항은.

자주 묻는 질문

Bluetooth Low Energy 플러그인 FAQ

Capacitor 앱에 Bluetooth Low Energy 플러그인을 어떻게 설치하나요?

"bun add @capgo/capacitor-bluetooth-low-energy" (또는 "npm install @capgo/capacitor-bluetooth-low-energy")를 실행한 다음, "bunx cap sync"를 실행하여 iOS 및 Android 프로젝트에 네이티브 code가 반영되도록 합니다. 그 후 앱의 code에서 "@capgo/capacitor-bluetooth-low-energy"를 통해 import 하세요.

@capgo/capacitor-bluetooth-low-energy가 React, Vue, Angular와 호환되나요?

네. Bluetooth Low Energy는 Capacitor 패키지이므로, Ionic, React, Vue, Angular, Svelte 및 일반 JavaScript를 포함하여 Capacitor 내에서 실행되는 모든 웹 프레임워크와 호환됩니다.

@capgo/capacitor-bluetooth-low-energy은 어떤 Capacitor 버전을 지원하나요?

Capgo 플러그인은 Capacitor의 메이저 버전을 따릅니다. 사용 중인 Capacitor 메이저 버전과 일치하는 플러그인 메이저 버전을 사용하세요 (예: Capacitor 8에는 플러그인 v8). 유지 관리되는 버전은 GitHub README의 호환성 표에서 확인할 수 있습니다.

@capgo/capacitor-bluetooth-low-energy는 무료이며 오픈 소스인가요?

네. code 소스 코드는 GitHub의 https://github.com/Cap-go/capacitor-bluetooth-low-energy/ 에 공개되어 있으며, 패키지는 npm에서 무료로 설치할 수 있습니다. 버그 리포트와 pull request를 환영합니다.

App Store 심사 없이 Bluetooth Low Energy를 사용하는 code를 업데이트할 수 있나요?

플러그인을 설치하거나 업그레이드하면 네이티브 code가 변경되므로 새로운 스토어 빌드가 필요합니다. 그 이후에는 플러그인을 호출하는 JavaScript, HTML, CSS 변경 사항을 Capgo live updates로 즉시 배포할 수 있습니다.

앱 심사 대기 없이 Bluetooth Low Energy 변경 사항을 즉시 배포하세요

스토어 빌드에 플러그인이 포함되면, Capgo live updates로 JavaScript, HTML, CSS 변경 사항을 몇 분 만에 사용자에게 푸시할 수 있습니다.

Capgo로 시작하기