Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import RNPermissions, {
PERMISSIONS,
RESULTS,
PermissionStatus,
Permission,
NotificationsResponse,
} from 'react-native-permissions';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {SIRI, ...PERMISSIONS_IOS} = PERMISSIONS.IOS; // remove siri (certificate required)
const PLATFORM_PERMISSIONS = Platform.select<
typeof PERMISSIONS_IOS | typeof PERMISSIONS.ANDROID | {}
>({
ios: PERMISSIONS_IOS,
android: PERMISSIONS.ANDROID,
default: {},
});
const PERMISSIONS_VALUES: Permission[] = Object.values(PLATFORM_PERMISSIONS);
const colors: {[key: string]: string} = {
unavailable: '#cfd8dc',
denied: '#ff9800',
granted: '#43a047',
blocked: '#e53935',
};
const icons: {[key: string]: string} = {
unavailable: 'lens',
denied: 'error',
granted: 'check-circle',
onPress: async () => {
setActiveTab(TabItems.Camera)
try {
const status = await check(
Platform.OS === 'ios' ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA,
)
if (status !== RESULTS.GRANTED) {
try {
const status = await request(
Platform.OS === 'ios' ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA,
)
if (status !== RESULTS.GRANTED) {
setSecurityAccessVisibility(true)
return
}
} catch (err) {
console.log(err)
}
}
} catch (err) {
console.log(err)
const acquireMicPerm = async (): Promise => {
try {
const status = await check(
Platform.OS === 'ios' ? PERMISSIONS.IOS.MICROPHONE : PERMISSIONS.ANDROID.RECORD_AUDIO,
)
if (status === RESULTS.GRANTED) {
return MicPermStatus.GRANTED
}
try {
const status = await request(
Platform.OS === 'ios' ? PERMISSIONS.IOS.MICROPHONE : PERMISSIONS.ANDROID.RECORD_AUDIO,
)
if (status === RESULTS.GRANTED) {
return MicPermStatus.NEWLY_GRANTED
}
return MicPermStatus.DENIED
} catch (err) {
console.log(err)
}
} catch (err) {
console.log(err)
}
return MicPermStatus.UNDEFINED
}
onPress={async () => {
setActivateTab(TabItems.Camera)
try {
const status = await check(
Platform.OS === 'ios' ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA,
)
if (status !== RESULTS.GRANTED) {
try {
const status = await request(
Platform.OS === 'ios'
? PERMISSIONS.IOS.CAMERA
: PERMISSIONS.ANDROID.CAMERA,
)
if (status !== RESULTS.GRANTED) {
setSecurityAccessVisibility(true)
return
}
} catch (err) {
console.log(err)
}
}
} catch (err) {
console.log(err)
}
try {
await ImagePicker.clean()
} catch (err) {}
try {
export const requestBluetoothPermission = async (): Promise => {
let permission =
Platform.OS === 'ios'
? PERMISSIONS.IOS.BLUETOOTH_PERIPHERAL
: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
try {
let result = await request(permission)
switch (result) {
case RESULTS.UNAVAILABLE:
console.log('Bluetooth is not available (on this device / in this context)')
break
case RESULTS.DENIED:
console.log('The Bluetooth permission has not been requested / is denied but requestable')
break
case RESULTS.LIMITED:
console.log('The Bluetooth permission is limited: some actions are possible')
break
case RESULTS.GRANTED:
console.log('The Bluetooth permission is granted')
return true
case RESULTS.BLOCKED:
Picker,
StatusBar,
ScrollView,
Platform,
} from 'react-native'
import Camera, {
Aspect,
CaptureQuality,
TorchMode,
RotateMode,
} from 'react-native-openalpr'
import { check, request, PERMISSIONS, RESULTS } from 'react-native-permissions'
const cameraPermission = Platform.select({
ios: PERMISSIONS.IOS.CAMERA,
android: PERMISSIONS.ANDROID.CAMERA,
})
const styles = StyleSheet.create({
container: {
flex: 1,
},
camera: {
flex: 1,
},
options: {
position: 'absolute',
top: 100,
left: 20,
right: 20,
bottom: 20,
borderRadius: 10,
Text,
Image,
Platform,
Dimensions
} from 'react-native';
import * as ImageManipulator from 'react-native-image-manipulator';
import { request, PERMISSIONS } from 'react-native-permissions';
import ImageEditor from './ImageEditor';
import * as MediaLibrary from 'react-native-media-library';
const { width } = Dimensions.get('window');
const PERMISSION =
Platform.OS === 'ios'
? PERMISSIONS.IOS.PHOTO_LIBRARY
: PERMISSIONS.ANDROID.READ_EXTERNAL_STORAGE;
const styles = {
container: {
flex: 1,
flexDirection: 'column',
backgroundColor: 'black'
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center'
},
capture: {
flex: 0,
backgroundColor: 'black',
borderRadius: 5,
export const requestBluetoothPermission = async (): Promise => {
let permission =
Platform.OS === 'ios'
? PERMISSIONS.IOS.BLUETOOTH_PERIPHERAL
: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
try {
let result = await request(permission)
if (result === RESULTS.GRANTED) {
return true
}
} catch (err) {}
return false
}
import {
check,
request,
PERMISSIONS,
PermissionStatus,
} from 'react-native-permissions'
import { Platform } from 'react-native'
import { ApolloClient } from 'apollo-client'
import { refreshWeather } from './weather'
const LOCATION_PERMISSION = Platform.select({
ios: PERMISSIONS.IOS.LOCATION_WHEN_IN_USE,
android: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
})
const { resolveLocationPermissionStatus, requestLocationPermission } = (() => {
let promise: Promise | undefined
const resolveLocationPermissionStatus = () => {
if (promise) return promise
promise = check(LOCATION_PERMISSION)
return promise
}
const requestLocationPermission = async (
apolloClient: ApolloClient,
): Promise => {
promise = request(LOCATION_PERMISSION)
const result = await promise
import {
check,
request,
PERMISSIONS,
PermissionStatus,
} from 'react-native-permissions'
import { Platform } from 'react-native'
import { ApolloClient } from 'apollo-client'
import { refreshWeather } from './weather'
const LOCATION_PERMISSION = Platform.select({
ios: PERMISSIONS.IOS.LOCATION_WHEN_IN_USE,
android: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
})
const { resolveLocationPermissionStatus, requestLocationPermission } = (() => {
let promise: Promise | undefined
const resolveLocationPermissionStatus = () => {
if (promise) return promise
promise = check(LOCATION_PERMISSION)
return promise
}
const requestLocationPermission = async (
apolloClient: ApolloClient,
): Promise => {
promise = request(LOCATION_PERMISSION)
const result = await promise