Skip to content

Commit

Permalink
added bluetooth permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Oct 15, 2024
1 parent 9fd3792 commit 70e7176
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apps/box/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ target 'Box' do
# Pods for testing
end

permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral"

post_install do |installer|
PLIST_BUDDY_PATH = '/usr/libexec/PlistBuddy'
# https://github.com/facebook/react-native/issues/34997
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
NativeEventEmitter,
NativeModules,
PermissionsAndroid,
Permission,
Platform,
StyleSheet,
} from 'react-native';
Expand All @@ -24,12 +25,21 @@ import BleManager, {
BleScanMode,
Peripheral,
} from 'react-native-ble-manager';
import { request, PERMISSIONS } from 'react-native-permissions';

const SECONDS_TO_SCAN_FOR = 5;
const ALLOW_DUPLICATES = false;
const BleManagerModule = NativeModules.BleManager;
const bleManagerEmitter = new NativeEventEmitter(BleManagerModule);

const requestIOSBluetoothPermission = async () => {
if (Platform.OS === 'ios') {
const result = await request(PERMISSIONS.IOS.BLUETOOTH);
return result === 'granted';
}
return true;
};

type ScanBluetoothModalProps = {
onSelect?: (item: Peripheral) => void;
};
Expand Down Expand Up @@ -85,7 +95,7 @@ const ScanBluetoothModal = React.forwardRef<
const scan = async () => {
try {
if (Platform.OS === 'android') {
const permissions = [];
const permissions: Permission[] = [];
if (Platform.Version >= 31) {
permissions.push(
...[
Expand All @@ -107,6 +117,9 @@ const ScanBluetoothModal = React.forwardRef<
)
)
return;
} else if (Platform.OS === 'ios') {
const granted = await requestIOSBluetoothPermission();
if (!granted) return;
}
setPeripherals(new Map());
setConnectedPeripherals(new Map());
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"react-native-modal": "^13.0.1",
"react-native-pager-view": "6.2.0",
"react-native-paper": "*",
"react-native-permissions": "^5.0.0",
"react-native-qrcode-svg": "^6.2.0",
"react-native-randombytes": "^3.6.1",
"react-native-reanimated": "~3.3.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15586,6 +15586,11 @@ react-native-paper@*:
color "^3.1.2"
use-latest-callback "^0.1.5"

react-native-permissions@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/react-native-permissions/-/react-native-permissions-5.0.0.tgz#fd7271ff6163341976882a5f331b710c97e84df1"
integrity sha512-H+njXissetO7DpWDqJ4J6AQBnmn4a9WQGGcn0Znm2wtb2IHEJkQooZH7yjYKqrgO6N4FkhuPiI7ZCuEDGLsPxQ==

react-native-qrcode-svg@^6.2.0:
version "6.3.2"
resolved "https://registry.yarnpkg.com/react-native-qrcode-svg/-/react-native-qrcode-svg-6.3.2.tgz#84b2bb37201589cff1ab58e7f7c884c5133fe47f"
Expand Down

0 comments on commit 70e7176

Please sign in to comment.