Skip to content

Commit

Permalink
fcm app fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ami-aman committed Sep 19, 2024
1 parent 5b8afe9 commit 7987067
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 38 deletions.
52 changes: 21 additions & 31 deletions Apps/FCM/src/screens/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NavigationProp, ParamListBase } from '@react-navigation/native';
import { PushPermissionStatus } from 'customerio-reactnative';
import { CioPushPermissionStatus } from 'customerio-reactnative';
import React from 'react';
import {
Image,
Expand Down Expand Up @@ -70,38 +70,36 @@ const Dashboard: React.FC<DashboardProps> = ({ navigation }) => {
Prompts.showSnackbar({ text: 'Event sent successfully' });
};

const handlePushPermissionCheck = () => {
getPushPermissionStatus().then((status: PushPermissionStatus) => {
switch (status) {
case PushPermissionStatus.Granted:
Prompts.showAlert({
title: pushPermissionAlertTitle,
message: 'Push notifications are enabled on this device',
});
break;

case PushPermissionStatus.Denied:
case PushPermissionStatus.NotDetermined:
requestPushPermission();
break;
}
});
const handlePushPermissionCheck = async () => {
const status = await getPushPermissionStatus();
switch (status) {
case CioPushPermissionStatus.Granted:
Prompts.showAlert({
title: pushPermissionAlertTitle,
message: 'Push notifications are enabled on this device',
});
break;

case CioPushPermissionStatus.Denied:
case CioPushPermissionStatus.NotDetermined:
requestPushPermission();
break;
}
};

const requestPushPermission = () => {
const requestPushPermission = async () => {
let options = { ios: { sound: true, badge: true } };

requestPushNotificationsPermission(options)
.then((status: PushPermissionStatus) => {
const status = await requestPushNotificationsPermission(options);
switch (status) {
case PushPermissionStatus.Granted:
case CioPushPermissionStatus.Granted:
Prompts.showSnackbar({
text: 'Push notifications are now enabled on this device',
});
break;

case PushPermissionStatus.Denied:
case PushPermissionStatus.NotDetermined:
case CioPushPermissionStatus.Denied:
case CioPushPermissionStatus.NotDetermined:
Prompts.showAlert({
title: pushPermissionAlertTitle,
message:
Expand All @@ -122,14 +120,6 @@ const Dashboard: React.FC<DashboardProps> = ({ navigation }) => {
});
break;
}
})
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.catch((error: any) => {
Prompts.showAlert({
title: pushPermissionAlertTitle,
message: 'Unable to request permission. Please try again later.',
});
});
};

const handleSettingsPress = () => {
Expand Down
15 changes: 8 additions & 7 deletions Apps/FCM/src/services/CustomerIOService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CioLogLevel,
CustomerIO
CustomerIO,
CioPushPermissionOptions
} from 'customerio-reactnative';
import User from '../data/models/user';
import CustomerIoSDKConfig from '../data/sdk/CustomerIoSDKConfig';
Expand Down Expand Up @@ -60,14 +61,14 @@ export const trackProfileAttribute = (name: string, value: any) => {
};

export const getPushPermissionStatus = () => {
// return CustomerIO.getPushPermissionStatus();
return CustomerIO.pushMessaging.getPushPermissionStatus();
};

// export const requestPushNotificationsPermission = (
// options: PushPermissionOptions,
// ) => {
// return CustomerIO.showPromptForPushNotifications(options);
// };
export const requestPushNotificationsPermission = (
options: typeof CioPushPermissionOptions,
) => {
return CustomerIO.pushMessaging.showPromptForPushNotifications(options);
};


export const registerInAppEventListener = () => {
Expand Down

0 comments on commit 7987067

Please sign in to comment.