react-native-ble-ios-sdt
v0.1.3
Published
desc
Readme
react-native-ble-ios-sdt
A React Native library for scanning Bluetooth Low Energy (BLE) peripherals on IOS.
Installation
Install the library:
npm install react-native-ble-ios-sdt npx pod-install iosLink the native modules (if React Native version < 0.60):
react-native link react-native-ble-ios-sdtHandle Permissions:
Ensure you have the necessary permissions configured in your Info.plist for iOS.
<key>NSBluetoothAlwaysUsageDescription</key> <string>We need access to Bluetooth to scan for devices.</string> <key>NSBluetoothPeripheralUsageDescription</key> <string>We need access to Bluetooth to scan for devices.</string>
Usage
import React from 'react';
import { View, Button, FlatList, Text } from 'react-native';
import { BLEModule } from 'react-native-ble-ios-sdt';
type Peripheral = {
id: string;
name: string;
rssi: number;
advertisementData: any;
};
const App = () => {
const [peripherals, setPeripherals] = useState<Peripheral[]>([]);
const handleScan = () => {
BLEManager.startScan((results) => {
setPeripherals(results);
});
};
const handleStop = () => {
BLEManager.stopScan();
};
return (
<View>
<Button title="Start Scan" onPress={handleScan} />
<Button title="Stop Scan" onPress={handleStop} />
<FlatList
data={peripherals}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<View>
<Text>{item.name}</Text>
<Text>{item.id}</Text>
<Text>{item.rssi}</Text>
<Text>{JSON.stringify(item.advertisementData)}</Text>
</View>
)}
/>
</View>
);
};
export default App;