Add notifications support.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import SignOutButton from "@/components-old/sign-out-button/sign-out-button.component";
|
||||
import { selectDeleteAfterUpload } from "@/redux/app/app.selectors";
|
||||
import { selectBodyshop, selectCurrentUser } from "@/redux/user/user.selectors";
|
||||
import { registerForPushNotificationsAsync } from "@/util/notificationHandler";
|
||||
import { formatBytes } from "@/util/uploadUtils";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import * as Application from "expo-application";
|
||||
import Constants from "expo-constants";
|
||||
import * as Notifications from "expo-notifications";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Alert, ScrollView, StyleSheet, View } from "react-native";
|
||||
import { Button, Card, Divider, List, Text } from "react-native-paper";
|
||||
@@ -107,7 +109,55 @@ function Tab({ bodyshop, currentUser }) {
|
||||
</View>
|
||||
</List.Section>
|
||||
</Card.Content>
|
||||
<Card.Actions></Card.Actions>
|
||||
<Card.Actions>
|
||||
<Button
|
||||
onPress={async () => {
|
||||
try {
|
||||
await registerForPushNotificationsAsync();
|
||||
} catch (error) {
|
||||
Alert.alert(
|
||||
"Error",
|
||||
`Unable to register for notifications: ${error.message}`
|
||||
);
|
||||
console.log("Notification registration error:", error);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Enable Notifications
|
||||
</Button>
|
||||
<Button
|
||||
onPress={async () => {
|
||||
const projectId =
|
||||
Constants?.expoConfig?.extra?.eas?.projectId ??
|
||||
Constants?.easConfig?.projectId;
|
||||
|
||||
const pushTokenString = (
|
||||
await Notifications.getExpoPushTokenAsync({
|
||||
projectId,
|
||||
})
|
||||
).data;
|
||||
const message = {
|
||||
to: pushTokenString,
|
||||
sound: "default",
|
||||
title: "Original Title",
|
||||
body: "And here is the body!",
|
||||
data: { someData: "goes here" },
|
||||
};
|
||||
|
||||
await fetch("https://exp.host/--/api/v2/push/send", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Accept-encoding": "gzip, deflate",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(message),
|
||||
});
|
||||
}}
|
||||
>
|
||||
Test Noti
|
||||
</Button>
|
||||
</Card.Actions>
|
||||
</Card>
|
||||
|
||||
<Card style={styles.section}>
|
||||
|
||||
Reference in New Issue
Block a user