Implement one signal and save token of user
This commit is contained in:
parent
7d6909f5c2
commit
195b9aaebc
5 changed files with 54 additions and 8 deletions
|
@ -5,6 +5,7 @@ import CalendarPicker from 'react-native-calendar-picker';
|
|||
import Ionicons from '@expo/vector-icons/Ionicons';
|
||||
import { useIsFocused } from '@react-navigation/core';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { LogLevel, OneSignal } from 'react-native-onesignal';
|
||||
|
||||
import { ThemedText } from '@/lib/components/ThemedText';
|
||||
import { ThemedView } from '@/lib/components/ThemedView';
|
||||
|
@ -13,6 +14,7 @@ import { useColorScheme } from '@/lib/hooks/useColorScheme';
|
|||
import { useToken } from '@/lib/context/AppProvider';
|
||||
import { Request } from '@/lib/services/request';
|
||||
import List from '@/lib/components/List';
|
||||
import { Message } from '@/lib/services/message';
|
||||
|
||||
export default function HomeScreen() {
|
||||
const colorScheme = useColorScheme() ?? 'light';
|
||||
|
@ -23,6 +25,37 @@ export default function HomeScreen() {
|
|||
const [ name, setName ] = useState( ' ' ); // Default empty space to prevent layout shifting
|
||||
const [ dates, setDates ] = useState<any | null>( [] );
|
||||
const [ types, setTypes ] = useState<any | null>( [] );
|
||||
const [ onesignalLoaded, setOnesignalLoaded ] = useState<any | null>( false );
|
||||
|
||||
const loadOneSignal = () => {
|
||||
// Remove this method to stop OneSignal Debugging
|
||||
OneSignal.Debug.setLogLevel(LogLevel.Verbose);
|
||||
|
||||
// OneSignal Initialization
|
||||
OneSignal.initialize("6ef15aa7-9dc0-4d8b-b6b1-e2005bcd3dc6");
|
||||
|
||||
// Request permission
|
||||
OneSignal.Notifications.requestPermission(true)
|
||||
|
||||
// Retrieve one signal user token
|
||||
OneSignal.User.pushSubscription.getIdAsync().then((notificationsToken) => {
|
||||
if (notificationsToken) {
|
||||
Request.post( 'sessions/update', { token: token, notifications_token: notificationsToken } ).then( (response) => {
|
||||
if (!response.success) {
|
||||
Message.error( 'Notificaties zijn uitgeschakeld door een onbekende error' );
|
||||
}
|
||||
} );
|
||||
}
|
||||
})
|
||||
|
||||
// Disable loading again
|
||||
setOnesignalLoaded(true);
|
||||
}
|
||||
|
||||
// Load OneSignal
|
||||
useEffect( () => {
|
||||
loadOneSignal();
|
||||
}, [onesignalLoaded] );
|
||||
|
||||
// Load session
|
||||
useEffect( () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue