Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function requestPermissionAsync(permission: Permissions.PermissionType) {
// Image Picker doesn't need permissions in the web
if (Platform.OS === 'web') {
return true;
}
const { status } = await Permissions.askAsync(permission);
return status === 'granted';
}
registerForPushNotificationsAsync = async () => {
if (Constants.isDevice) {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(
Permissions.NOTIFICATIONS
);
finalStatus = status;
}
if (finalStatus !== 'granted') {
alert('Failed to get push token for push notification!');
return;
}
let token = await Notifications.getExpoPushTokenAsync();
this._onSetPushToken(token);
} else {
// alert('Must use physical device for Push Notifications');
}
await scheduleMoodReminders();
};
handleUploadImage = () => {
Permissions.askAsync(Permissions.CAMERA_ROLL)
.then((response) => {
const { status } = response
if (status === 'granted') {
ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [1, 1],
base64: true,
quality: 0.5,
})
.then((response) => {
if (!response.cancelled) {
this.props.uploadImage(response.uri)
}
})
.catch((error) => console.log(error))
}
_obtainUserFacingNotifPermissionsAsync = async () => {
let permission = await Permissions.getAsync(
Permissions.USER_FACING_NOTIFICATIONS
);
if (permission.status !== 'granted') {
permission = await Permissions.askAsync(
Permissions.USER_FACING_NOTIFICATIONS
);
if (permission.status !== 'granted') {
Alert.alert(`We don't have permission to present notifications.`);
}
}
return permission;
}
export default async function getPermissionAsync(permission) {
const { status } = await Permissions.askAsync(permission)
if (status !== 'granted') {
const permissionName = permission.toLowerCase().replace('_', ' ')
Alert.alert(
'Cannot be done 😞',
`If you would like to use this feature, you'll need to enable the ${permissionName} permission in your phone settings.`,
[
{
text: "Let's go!",
onPress: () => Linking.openURL('app-settings:'),
},
{ text: 'Nevermind', onPress: () => {}, style: 'cancel' },
],
{ cancelable: true },
)
return false
private onAddButtonPress = (): void => {
Permissions.askAsync(Permissions.CAMERA_ROLL)
.then(this.onCameraPermissionResponse);
};
) => (error: any): Promise => {
if (error.code === 'E_MISSING_PERMISSION' && retryFn) {
return Permissions.askAsync(...perms).then(retryFn)
} else {
throw error
}
}