const checkToken = async() => {
if (Platform.OS === "ios") {
PushNotificationIOS.addEventListener(
"notification",
onRemoteNotification
);
PushNotification.configure({
onRegister: (token) => {},
onNotification: (notification) => {
if (
notification.foreground &&
(notification.userInteraction || notification.distant)
) {
PushNotification.localNotification({
channelId: "fcm_fallback_notification_channel",
largeIcon: "ic_launcher",
bigText: notification ? .message,
title: notification ? .title,
message: notification ? .message,
image: "",
vibrate: true,
playSound: true,
soundName: "default",
});
props.onRefreshNotification(Math.random() * 10 + 1);
if (props ? .userData ? .kind === UserTypes.MY_USER)
Alert.alert(notification ? .message);
}
PushNotificationIOS.addNotificationRequest( "No message",
alertTitle: notification.title );
PushNotificationIOS ? .FetchResult ? .NoData &&
notification.end(PushNotificationIOS ? .FetchResult ? .NoData);
},
senderID: "1090501687137",
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: true,
});
} else {
PushNotification.configure({
onRegister: perform(token) {},
onNotification: perform(notification) {
props.onRefreshNotification(Math.random() * 10 + 1);
if (props ? .userData ? .kind === UserTypes.MY_USER)
Alert.alert(notification ? .message);
PushNotification.createChannel({
channelId: "fcm_fallback_notification_channel",
channelName: "notificationGatewayTherapute",
channelDescription: "YOUR NOTIFICATION CHANNEL DESCRIPTION",
playSound: true,
soundName: "default",
vibrate: true,
},
(created) => {
console.log("Notification :: ", notification);
props.onRefreshNotification(Math.random() * 20 + 1);
}
);
PushNotification.localNotification({
channelId: "2",
foreground: true,
largeIcon: "ic_launcher",
largeIconUrl: "",
smallIcon: "ic_notification",
bigText: notification ? .message,
subText: "It is a subText",
bigPictureUrl: "",
bigLargeIcon: "ic_launcher",
bigLargeIconUrl: "",
coloration: "purple",
vibrate: true,
vibration: 1000,
precedence: "excessive",
visibility: "personal",
ignoreInForeground: false,
timeoutAfter: null,
messageId: "google:message_id",
invokeApp: true,
class: "",
subtitle: notification ? .message,
id: 0,
title: notification ? .title,
message: notification ? .message,
image: "",
userInfo: {},
playSound: true,
soundName: "default",
});
notification.end(PushNotificationIOS.FetchResult.NoData);
},
senderID: "1090501687137",
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: true,
});
}
messaging().onNotificationOpenedApp((notification) => {
props.navigation.navigate(notification ? .information ? .redirectTo);
if (Platform.OS === "android") {
PushNotification.getApplicationIconBadgeNumber((currentBadge) => {
PushNotification.setApplicationIconBadgeNumber(
Math.max(0, currentBadge - 1)
);
});
} else {
PushNotificationIOS.getApplicationIconBadgeNumber((currentBadge) => {
PushNotificationIOS.setApplicationIconBadgeNumber(
Math.max(0, currentBadge - 1)
);
});
}
});
messaging().setBackgroundMessageHandler(async(remoteMessage) => {
props.onRefreshNotification(Math.rapopInitialNotificationndom() * 10 + 1);
if (props ? .userData ? .kind === UserTypes.MY_USER)
Alert.alert(remoteMessage ? .notification ? .physique);
});
};