I am fairly new to react-native and expo and still learning. I am trying to configure local notifications for an android device, but it’s not working. While trying to solve this issue, I learned that Permissions has moved out of expo, and Notifications for android require a separate object to be created for sound and vibration to work. The examples on the google do not seem to work. (maybe due to SDK version difference). I have already tried importing “Permissions” from the new “expo-permissions” but still, it is not working! Please help!!
SDK Versions are:
expo: 36.0.0,
expo-permissions: 8.0.0
Here is my code:
import Notifications from 'expo';
import * as Permissions from 'expo-permissions';
async obtainNotificationPermission() {
let permission = await Permissions.getAsync(Permissions.USER_FACING_NOTIFICATIONS)
if (permission.status !== 'granted') {
permission =await Permissions.askAsync(Permissions.USER_FACING_NOTIFICATION);
console.log("Permission Status: "+permission);
if (permission.status !== 'granted') {
Alert.alert('Permission not granted to show notifications!')
}
}
return permission;
}
async presentLocalNotification(date) {
await this.obtainNotificationPermission();
console.log("Permission Status: "+this.obtainNotificationPermission());
Notifications.presentLocalNotificationAsync({
title: 'Your Reservation',
body: 'Reservation for '+ date + ' requested',
ios: {
sound: true
},
android: {
sound: true,
vibrate: true,
color: '#512DA8'
}
});
}