forked from Hamzadar007/CodePushRN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
92 lines (76 loc) · 2.25 KB
/
Copy pathApp.tsx
File metadata and controls
92 lines (76 loc) · 2.25 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React, { useEffect } from 'react';
import {
AppState,
Button,
SafeAreaView,
Text,
} from 'react-native';
import messaging from '@react-native-firebase/messaging';
import codePush from "react-native-code-push";
import CodePush from "react-native-code-push";
import {
checkNotifications,
requestNotifications,
} from "react-native-permissions";
let codePushOptions = {
checkFrequency: CodePush.CheckFrequency.ON_APP_RESUME,
installMode: CodePush.InstallMode.IMMEDIATE,
updateDialog: {
title: "Update available",
optionalUpdateMessage:
"An update is available. Would you like to install it?",
mandatoryUpdateMessage:
"An update is available and needs to be installed. Your app will refresh after the update is complete.",
optionalIgnoreButtonLabel: "Later",
optionalInstallButtonLabel: "Install",
},
};
function App(): React.JSX.Element {
const checkNotificationPermission = async () => {
if (true) {
checkNotifications().then(({ status, settings }) => {
if (status == "granted") {
messagingRequest();
} else if (status == "denied") {
requestNotifications(["alert", "sound"]).then(
({ status, settings }) => {
if (status == "granted") {
messagingRequest();
}
}
);
}
});
} else {
messagingRequest();
}
};
async function messagingRequest() {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);
}
}
const getToke=async ()=>{
try {
const token = await messaging().getToken()
console.log('FCM Token:', token);
} catch (error) {
console.log("error:", error);
}
}
useEffect(()=>{
checkNotificationPermission();
getToke()
},[])
return (
<SafeAreaView style={{flex:1,justifyContent:'center',alignItems:'center'}}>
<Text>Hamza Dar Code Push Test</Text>
<Button onPress={()=>{}} title='Click me'/>
</SafeAreaView>
);
}
export default codePush(codePushOptions)( App);