-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathApp.tsx
More file actions
76 lines (68 loc) · 2.23 KB
/
Copy pathApp.tsx
File metadata and controls
76 lines (68 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* eslint-disable react-native/split-platform-components */
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { useEffect } from 'react';
import { PermissionsAndroid, Platform } from 'react-native';
import { Route } from '../../constants/routes';
import { useIterableApp } from '../../hooks/useIterableApp';
import type { RootStackParamList } from '../../types';
import { Login } from '../Login';
import { Main } from './Main';
const Stack = createNativeStackNavigator<RootStackParamList>();
const requestNotificationPermission = async () => {
if (Platform.OS === 'android') {
const apiLevel = Platform.Version; // Get the Android API level
if (apiLevel >= 33) {
// Check if Android 13 or higher
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
{
title: 'Notification Permission',
message:
'This app needs access to your notifications for push, in-app messages, embedded messages and more.',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('Notification permission granted');
} else {
console.log('Notification permission denied');
}
} catch (err) {
console.warn(err);
}
} else {
// For Android versions below 13, notification permission is generally not required
// or is automatically granted upon app installation.
console.log(
'Notification permission not required for this Android version.'
);
}
}
};
export const App = () => {
const { isLoggedIn } = useIterableApp();
useEffect(() => {
requestNotificationPermission();
}, []);
return (
<Stack.Navigator>
{isLoggedIn ? (
<Stack.Screen
name={Route.Main}
component={Main}
options={{ headerShown: false }}
/>
) : (
<Stack.Screen
name={Route.Login}
component={Login}
options={{ headerShown: false }}
/>
)}
</Stack.Navigator>
);
};
export default App;