본문 바로가기

블루투스 저에너지 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 플러그인

설치

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 서버에 characteristics가 포함된 GATT 서비스를 추가합니다. 광고를 시작하기 전에 peripheral mode에서 호출해야 합니다.
removeGattService 로컬 GATT 서버에서 GATT 서비스를 제거합니다.
setGattCharacteristicValue 로컬 GATT characteristic의 값을 설정합니다.
notifyGattCharacteristicChanged 연결된 centrals에 로컬 GATT characteristic 값이 변경되었음을 알립니다.
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.bluetooth. Capacitor 네이티브 앱에서 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")을 실행한 다음, iOS와 Android 프로젝트가 네이티브 code를 인식하도록 "bunx cap sync"를 실행하세요. 앱 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는 https://github.com/Cap-go/capacitor-bluetooth-low-energy/의 GitHub에 공개되어 있고, npm에서 무료로 설치할 수 있습니다. 버그 리포트와 풀 리퀘스트는 언제나 환영합니다.

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

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

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

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

Capgo로 시작하기