diff --git a/Apps/FCM/src/screens/Dashboard.tsx b/Apps/FCM/src/screens/Dashboard.tsx index c7145efc..2ea5020a 100644 --- a/Apps/FCM/src/screens/Dashboard.tsx +++ b/Apps/FCM/src/screens/Dashboard.tsx @@ -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, @@ -70,38 +70,36 @@ const Dashboard: React.FC = ({ 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: @@ -122,14 +120,6 @@ const Dashboard: React.FC = ({ 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 = () => { diff --git a/Apps/FCM/src/services/CustomerIOService.ts b/Apps/FCM/src/services/CustomerIOService.ts index 4211b62d..75918eb5 100644 --- a/Apps/FCM/src/services/CustomerIOService.ts +++ b/Apps/FCM/src/services/CustomerIOService.ts @@ -1,6 +1,7 @@ import { CioLogLevel, - CustomerIO + CustomerIO, + CioPushPermissionOptions } from 'customerio-reactnative'; import User from '../data/models/user'; import CustomerIoSDKConfig from '../data/sdk/CustomerIoSDKConfig'; @@ -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 = () => {