admin管理员组文章数量:1026961
I am working on a test suite for a react native app that requires bluetooth permissions to work. I know this is common for apps like ours but, for some reason, there is not a bluetooth option for permissions applied like this:
await device.launchApp({ permissions: { bluetooth: 'YES' } });
Is there another way to accept bluetooth permissions? I have read through documentation and done some searching with no luck so far.
await device.launchApp({ permissions: { bluetooth: 'YES' } });
Expectation: Bluetooth permissions are accepted
Actual: bluetooth is not an option in applesimutils for permissions
I am working on a test suite for a react native app that requires bluetooth permissions to work. I know this is common for apps like ours but, for some reason, there is not a bluetooth option for permissions applied like this:
await device.launchApp({ permissions: { bluetooth: 'YES' } });
Is there another way to accept bluetooth permissions? I have read through documentation and done some searching with no luck so far.
await device.launchApp({ permissions: { bluetooth: 'YES' } });
Expectation: Bluetooth permissions are accepted
Actual: bluetooth is not an option in applesimutils for permissions
Share Improve this question asked Nov 16, 2024 at 16:32 Kristi FarrellKristi Farrell 111 bronze badge1 Answer
Reset to default 0You might take a look at this answer
It requires @config-plugins/react-native-ble-plx and react-native-ble-plx ;
npx expo install react-native-ble-plx @config-plugins/react-native-ble-plx
If you use Expo (if not, you should) add this to your app.json
or app.config.js
;
{
"expo": {
"plugins": ["@config-plugins/react-native-ble-plx"]
}
}
Then take a look at the documentation here.
import { BleManager } from 'react-native-ble-plx'
export const manager = new BleManager()
export const requestBluetoothPermission = async () => {
if (Platform.OS === 'ios') {
return true
}
if (Platform.OS === 'android' && PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION) {
const apiLevel = parseInt(Platform.Version.toString(), 10)
if (apiLevel < 31) {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION)
return granted === PermissionsAndroid.RESULTS.GRANTED
}
if (PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN && PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT) {
const result = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
])
return (
result['android.permission.BLUETOOTH_CONNECT'] === PermissionsAndroid.RESULTS.GRANTED &&
result['android.permission.BLUETOOTH_SCAN'] === PermissionsAndroid.RESULTS.GRANTED &&
result['android.permission.ACCESS_FINE_LOCATION'] === PermissionsAndroid.RESULTS.GRANTED
)
}
}
return false
}
Note: iOS does not need a request permission like Android does
I am working on a test suite for a react native app that requires bluetooth permissions to work. I know this is common for apps like ours but, for some reason, there is not a bluetooth option for permissions applied like this:
await device.launchApp({ permissions: { bluetooth: 'YES' } });
Is there another way to accept bluetooth permissions? I have read through documentation and done some searching with no luck so far.
await device.launchApp({ permissions: { bluetooth: 'YES' } });
Expectation: Bluetooth permissions are accepted
Actual: bluetooth is not an option in applesimutils for permissions
I am working on a test suite for a react native app that requires bluetooth permissions to work. I know this is common for apps like ours but, for some reason, there is not a bluetooth option for permissions applied like this:
await device.launchApp({ permissions: { bluetooth: 'YES' } });
Is there another way to accept bluetooth permissions? I have read through documentation and done some searching with no luck so far.
await device.launchApp({ permissions: { bluetooth: 'YES' } });
Expectation: Bluetooth permissions are accepted
Actual: bluetooth is not an option in applesimutils for permissions
Share Improve this question asked Nov 16, 2024 at 16:32 Kristi FarrellKristi Farrell 111 bronze badge1 Answer
Reset to default 0You might take a look at this answer
It requires @config-plugins/react-native-ble-plx and react-native-ble-plx ;
npx expo install react-native-ble-plx @config-plugins/react-native-ble-plx
If you use Expo (if not, you should) add this to your app.json
or app.config.js
;
{
"expo": {
"plugins": ["@config-plugins/react-native-ble-plx"]
}
}
Then take a look at the documentation here.
import { BleManager } from 'react-native-ble-plx'
export const manager = new BleManager()
export const requestBluetoothPermission = async () => {
if (Platform.OS === 'ios') {
return true
}
if (Platform.OS === 'android' && PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION) {
const apiLevel = parseInt(Platform.Version.toString(), 10)
if (apiLevel < 31) {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION)
return granted === PermissionsAndroid.RESULTS.GRANTED
}
if (PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN && PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT) {
const result = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
])
return (
result['android.permission.BLUETOOTH_CONNECT'] === PermissionsAndroid.RESULTS.GRANTED &&
result['android.permission.BLUETOOTH_SCAN'] === PermissionsAndroid.RESULTS.GRANTED &&
result['android.permission.ACCESS_FINE_LOCATION'] === PermissionsAndroid.RESULTS.GRANTED
)
}
}
return false
}
Note: iOS does not need a request permission like Android does
本文标签: React Native Detox Accept Bluetooth PermissionsStack Overflow
版权声明:本文标题:React Native Detox: Accept Bluetooth Permissions - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745652094a2161378.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论