app folder
|
@ -0,0 +1,245 @@
|
||||||
|
|
||||||
|
import 'react-native-gesture-handler';
|
||||||
|
import * as React from 'react';
|
||||||
|
import { Platform, AppState } from 'react-native';
|
||||||
|
import { Provider } from "react-redux";
|
||||||
|
import firebase from '@react-native-firebase/app';
|
||||||
|
import '@react-native-firebase/messaging';
|
||||||
|
import { NativeBaseProvider } from 'native-base';
|
||||||
|
import Router from './screens/route.js';
|
||||||
|
import store from './redux/store';
|
||||||
|
|
||||||
|
import DeviceInfo from 'react-native-device-info';
|
||||||
|
import DB from './components/storage/';
|
||||||
|
|
||||||
|
var PushNotification = require("react-native-push-notification");
|
||||||
|
|
||||||
|
export default class App extends React.Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
}
|
||||||
|
|
||||||
|
_isMounted = false
|
||||||
|
state = {
|
||||||
|
appState: AppState.currentState,
|
||||||
|
backgroundCaptureTime: null
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentDidMount() {
|
||||||
|
this._isMounted = true
|
||||||
|
this.saveDeviceUUID()
|
||||||
|
this.notificationAuthorization()
|
||||||
|
this.createNotificationListener()
|
||||||
|
AppState.addEventListener('change', this._handleAppStateChange)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this._isMounted = false
|
||||||
|
try {
|
||||||
|
this.messageListener()
|
||||||
|
this.notificationOpenedListener()
|
||||||
|
this.notificationListener()
|
||||||
|
AppState.removeEventListener('change', this._handleAppStateChange)
|
||||||
|
} catch (error) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleAppStateChange = (nextAppState) => {
|
||||||
|
if(this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveDeviceUUID = () => {
|
||||||
|
DB.set("deviceUUID", DeviceInfo.getUniqueId(), () => {}, (e) => console.log("DEVICE INFO SAVING FAILED!", e))
|
||||||
|
}
|
||||||
|
|
||||||
|
notificationAuthorization = async () => {
|
||||||
|
const authStatus = await firebase.messaging().requestPermission();
|
||||||
|
const enabled = authStatus === firebase.messaging.AuthorizationStatus.AUTHORIZED || authStatus === firebase.messaging.AuthorizationStatus.PROVISIONAL;
|
||||||
|
if (enabled) {
|
||||||
|
try {
|
||||||
|
const token = await firebase.messaging().getToken()
|
||||||
|
if(token) {
|
||||||
|
let existingToken = await DB.get("fcmToken") || ""
|
||||||
|
if(token != existingToken){
|
||||||
|
DB.set("fcmRegistration", "new", (r) => {}, (e) => {})
|
||||||
|
DB.set("fcmToken", token, () => console.log("FCM TOKEN SAVED", token), () => console.log("FCM TOKEN SAVING FAILED"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('device_token:', token);
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createNotificationListener = () => {
|
||||||
|
this.messageListener = firebase.messaging().onMessage(message => {
|
||||||
|
const { notification } = message
|
||||||
|
PushNotification.localNotification({
|
||||||
|
title: notification.title || "Unioil Loyalty App",
|
||||||
|
message: notification.body,
|
||||||
|
playSound: false,
|
||||||
|
soundName: "default"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Triggered when a particular notification has been received in foreground
|
||||||
|
* */
|
||||||
|
this.notificationListener = firebase.messaging().onMessage(async remoteMessage => {
|
||||||
|
console.log(remoteMessage)
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If your app is in background, you can listen for when a notification is clicked / tapped / opened as follows:
|
||||||
|
* */
|
||||||
|
this.notificationOpenedListener = firebase.messaging().onNotificationOpenedApp(remoteMessage => {
|
||||||
|
console.log(remoteMessage)
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
firebase.messaging()
|
||||||
|
.getInitialNotification()
|
||||||
|
.then(async remoteMessage => {
|
||||||
|
if (remoteMessage) {
|
||||||
|
if(Platform.OS == 'ios'){
|
||||||
|
console.log(
|
||||||
|
'Notification caused app to open from quit state:',
|
||||||
|
remoteMessage.data.notification,
|
||||||
|
);
|
||||||
|
let result = await DB.AddNotification({
|
||||||
|
messageId: remoteMessage.data.from,
|
||||||
|
title: remoteMessage.data.notification.title,
|
||||||
|
body: remoteMessage.data.notification.body,
|
||||||
|
visible: true,
|
||||||
|
delivery: false,
|
||||||
|
recieved: remoteMessage.data.from
|
||||||
|
})
|
||||||
|
console.log("Notifications rendered on background", result)
|
||||||
|
}else{
|
||||||
|
console.log(
|
||||||
|
'Notification caused app to open from quit state:',
|
||||||
|
remoteMessage.notification,
|
||||||
|
);
|
||||||
|
let result = await DB.AddNotification({
|
||||||
|
messageId: remoteMessage.messageId,
|
||||||
|
title: remoteMessage.notification.title,
|
||||||
|
body: remoteMessage.notification.body,
|
||||||
|
visible: true,
|
||||||
|
delivery: false,
|
||||||
|
recieved: remoteMessage.sentTime
|
||||||
|
})
|
||||||
|
console.log("Notifications rendered on background", result)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Provider store={store}>
|
||||||
|
<NativeBaseProvider>
|
||||||
|
<Router/>
|
||||||
|
</NativeBaseProvider>
|
||||||
|
</Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// export default function App(){
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// const uniqueId = DeviceInfo.getUniqueId();
|
||||||
|
// DB.set("deviceUUID", uniqueId, function(){
|
||||||
|
// }, function(e){
|
||||||
|
// console.log("DEVICE INFO SAVING FAILED!", e)
|
||||||
|
// })
|
||||||
|
// }, [])
|
||||||
|
|
||||||
|
// const GetFCMToken = () => {
|
||||||
|
// messaging().getToken().then(async fcmToken => {
|
||||||
|
// if(fcmToken){
|
||||||
|
// let existingToken = await DB.get("fcmToken") || ""
|
||||||
|
// if(fcmToken != existingToken){
|
||||||
|
// DB.set("fcmRegistration", "new", (r) => console.log(r), (e) => console.log(e))
|
||||||
|
// DB.set("fcmToken", fcmToken, () => console.log("FCM TOKEN SAVED"), () => console.log("FCM TOKEN SAVING FAILED"))
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const NotificationAuthorization = async () => {
|
||||||
|
// await messaging().registerDeviceForRemoteMessages();
|
||||||
|
// const enabled = await messaging().hasPermission()
|
||||||
|
// if (!enabled) {
|
||||||
|
// try {
|
||||||
|
// await messaging().requestPermission()
|
||||||
|
// } catch (error) {
|
||||||
|
// // permission denied
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// GetFCMToken()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// if(Platform.OS === 'ios'){
|
||||||
|
// NotificationAuthorization()
|
||||||
|
// }else{
|
||||||
|
// GetFCMToken()
|
||||||
|
// }
|
||||||
|
// }, [])
|
||||||
|
|
||||||
|
// useEffect(() => {
|
||||||
|
// messaging()
|
||||||
|
// .getInitialNotification()
|
||||||
|
// .then(async remoteMessage => {
|
||||||
|
// if (remoteMessage) {
|
||||||
|
|
||||||
|
// if(Platform.OS == 'ios'){
|
||||||
|
// console.log(
|
||||||
|
// 'Notification caused app to open from quit state:',
|
||||||
|
// remoteMessage.data.notification,
|
||||||
|
// );
|
||||||
|
// let result = await DB.AddNotification({
|
||||||
|
// messageId: remoteMessage.data.from,
|
||||||
|
// title: remoteMessage.data.notification.title,
|
||||||
|
// body: remoteMessage.data.notification.body,
|
||||||
|
// visible: true,
|
||||||
|
// delivery: false,
|
||||||
|
// recieved: remoteMessage.data.from
|
||||||
|
// })
|
||||||
|
// console.log("Notifications rendered on background", result)
|
||||||
|
// }else{
|
||||||
|
// console.log(
|
||||||
|
// 'Notification caused app to open from quit state:',
|
||||||
|
// remoteMessage.notification,
|
||||||
|
// );
|
||||||
|
// let result = await DB.AddNotification({
|
||||||
|
// messageId: remoteMessage.messageId,
|
||||||
|
// title: remoteMessage.notification.title,
|
||||||
|
// body: remoteMessage.notification.body,
|
||||||
|
// visible: true,
|
||||||
|
// delivery: false,
|
||||||
|
// recieved: remoteMessage.sentTime
|
||||||
|
// })
|
||||||
|
// console.log("Notifications rendered on background", result)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// }, [])
|
||||||
|
|
||||||
|
// return (
|
||||||
|
// <Provider store={store}>
|
||||||
|
// <Root>
|
||||||
|
// <Router />
|
||||||
|
// </Root>
|
||||||
|
// </Provider>
|
||||||
|
// )
|
||||||
|
// }
|
After Width: | Height: | Size: 104 KiB |
After Width: | Height: | Size: 69 KiB |
After Width: | Height: | Size: 724 B |
After Width: | Height: | Size: 236 B |
After Width: | Height: | Size: 347 B |
After Width: | Height: | Size: 533 B |
After Width: | Height: | Size: 541 B |
After Width: | Height: | Size: 351 B |
After Width: | Height: | Size: 345 B |
After Width: | Height: | Size: 108 KiB |
After Width: | Height: | Size: 5.2 MiB |
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 236 KiB |
After Width: | Height: | Size: 4.8 MiB |
After Width: | Height: | Size: 176 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 315 KiB |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 51 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 291 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 102 B |
After Width: | Height: | Size: 965 B |
After Width: | Height: | Size: 758 B |
After Width: | Height: | Size: 714 B |
After Width: | Height: | Size: 725 B |
After Width: | Height: | Size: 505 B |
After Width: | Height: | Size: 436 B |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 866 B |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 6.2 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 915 B |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 966 B |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 2.8 MiB |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 501 KiB |
After Width: | Height: | Size: 306 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 81 KiB |
After Width: | Height: | Size: 391 KiB |
After Width: | Height: | Size: 5.7 MiB |
After Width: | Height: | Size: 5.2 MiB |
After Width: | Height: | Size: 385 KiB |
After Width: | Height: | Size: 5.5 MiB |
After Width: | Height: | Size: 4.5 MiB |
After Width: | Height: | Size: 54 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 15 KiB |