설치
라이브러리 설치
$ yarn add react-native-ble-manager
Android - manifest 파일 수정 (블루투스 권한 관련)
프로젝트루트/android/app/src/main/AndroidManifest.xml
아래 빨간색 표시한 부분을 추가한다.
xmlns:tools="http://schemas.android.com/tools" ← 를 추가하는 것을 빼먹지 말자
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.awesometsproject"> ... <!-- 블루투스 권한을 위해 아래 권한들을 추가한다 --> <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="28"/> <uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" xmlns:tools="http://schemas.android.com/tools" tools:targetApi="Q"/> <!-- Only when targeting Android 12 or higher --> <!-- Please make sure you read the following documentation to have a better understanding of the new permissions. https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#assert-never-for-location --> <!-- If your app doesn't use Bluetooth scan results to derive physical location information, you can strongly assert that your app doesn't derive physical location. --> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" android:usesPermissionFlags="neverForLocation" tools:targetApi="s" /> <!-- Needed only if your app looks for Bluetooth devices. --> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <!-- Needed only if your app makes the device discoverable to Bluetooth devices. --> <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" /> ... <application ... </application> </manifest>
연결 시도 시 반환값 예시
LOG Connected to B4:52:A9:CD:A0:E8 LOG Retrieved peripheral services {"advertising": {"isConnectable": true, "localName": "ACR1255U-J1-024851", "manufacturerData": {"CDVType": "ArrayBuffer", "bytes": [Array], "data": "AgEGEQYz8Y5xSNODqeU9g0fw/0o8EwlBQ1IxMjU1VS1KMS0wMjQ4NTEAAAAAAAAAAAAAAAAAAAAAAAAAAAA="}, "serviceData": {}, "serviceUUIDs": ["3c4afff0-4783-3de5-a983-d348718ef133"], "txPowerLevel": -2147483648}, "characteristics": [{"characteristic": "2a00", "properties": [Object], "service": "1800"}, {"characteristic": "2a01", "properties": [Object], "service": "1800"}, {"characteristic": "2a02", "properties": [Object], "service": "1800"}, {"characteristic": "2a03", "properties": [Object], "service": "1800"}, {"characteristic": "2a04", "properties": [Object], "service": "1800"}, {"characteristic": "2a05", "descriptors": [Array], "properties": [Object], "service": "1801"}, {"characteristic": "2a23", "properties": [Object], "service": "180a"}, {"characteristic": "2a24", "properties": [Object], "service": "180a"}, {"characteristic": "2a25", "properties": [Object], "service": "180a"}, {"characteristic": "2a26", "properties": [Object], "service": "180a"}, {"characteristic": "2a27", "properties": [Object], "service": "180a"}, {"characteristic": "2a28", "properties": [Object], "service": "180a"}, {"characteristic": "2a29", "properties": [Object], "service": "180a"}, {"characteristic": "2a2a", "properties": [Object], "service": "180a"}, {"characteristic": "2a50", "properties": [Object], "service": "180a"}, {"characteristic": "2a19", "descriptors": [Array], "properties": [Object], "service": "180f"}, {"characteristic": "3c4afff1-4783-3de5-a983-d348718ef133", "descriptors": [Array], "properties": [Object], "service": "3c4afff0-4783-3de5-a983-d348718ef133"}, {"characteristic": "3c4afff2-4783-3de5-a983-d348718ef133", "descriptors": [Array], "properties": [Object], "service": "3c4afff0-4783-3de5-a983-d348718ef133"}, {"characteristic": "3c4afff3-4783-3de5-a983-d348718ef133", "descriptors": [Array], "properties": [Object], "service": "3c4afff0-4783-3de5-a983-d348718ef133"}], "id": "B4:52:A9:CD:A0:E8", "name": "ACR1255U-J1-024851", "rssi": -55, "services": [{"uuid": "1800"}, {"uuid": "1801"}, {"uuid": "180a"}, {"uuid": "180f"}, {"uuid": "3c4afff0-4783-3de5-a983-d348718ef133"}]} LOG Retrieved actual RSSI value -52
Default Customer Master Key (Hex):
41 43 52 31 32 35 35 55 2D 4A 31 20 41 75 74 68
6번 이상의 incorrect 인증 키가 입력되면 locked 되고 사용할 수 없다.