Some cleaning on notifs
This commit is contained in:
37
App.js
37
App.js
@@ -32,14 +32,27 @@ const theme = {
|
||||
};
|
||||
|
||||
Notifications.setNotificationHandler({
|
||||
handleNotification: async () => ({
|
||||
shouldShowAlert: true,
|
||||
shouldPlaySound: false,
|
||||
shouldSetBadge: false,
|
||||
}),
|
||||
handleNotification: async () => {
|
||||
//console.log("notif background");
|
||||
return {
|
||||
shouldShowAlert: true,
|
||||
shouldPlaySound: true,
|
||||
shouldSetBadge: true,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
async function registerForPushNotificationsAsync() {
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
Notifications.setNotificationChannelAsync('default', {
|
||||
name: 'default',
|
||||
importance: Notifications.AndroidImportance.MAX,
|
||||
vibrationPattern: [0, 250, 250, 250],
|
||||
lightColor: '#FF231F7C',
|
||||
});
|
||||
}
|
||||
|
||||
let token;
|
||||
if (Device.isDevice) {
|
||||
const { status: existingStatus } = await Notifications.getPermissionsAsync();
|
||||
@@ -53,21 +66,9 @@ async function registerForPushNotificationsAsync() {
|
||||
return;
|
||||
}
|
||||
token = (await Notifications.getExpoPushTokenAsync({ projectId: "c2bb4d4e-4d4d-4f34-a873-7cad78c6023c", })).data;
|
||||
console.log(token);
|
||||
} else {
|
||||
alert('Must use physical device for Push Notifications');
|
||||
}
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
Notifications.setNotificationChannelAsync('default', {
|
||||
name: 'default',
|
||||
importance: Notifications.AndroidImportance.MAX,
|
||||
vibrationPattern: [0, 250, 250, 250],
|
||||
lightColor: '#FF231F7C',
|
||||
});
|
||||
}
|
||||
|
||||
console.log(token);
|
||||
return token;
|
||||
}
|
||||
|
||||
@@ -89,11 +90,13 @@ const MainNavigation = () => {
|
||||
|
||||
// This listener is fired whenever a notification is received while the app is foregrounded
|
||||
notificationListener.current = Notifications.addNotificationReceivedListener(notification => {
|
||||
//console.log("got notif", notification)
|
||||
setNotification(notification);
|
||||
});
|
||||
|
||||
// This listener is fired whenever a user taps on or interacts with a notification (works when app is foregrounded, backgrounded, or killed)
|
||||
responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
|
||||
//console.log("got notif click", notification)
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user