Skip to content

Commit

Permalink
Android notification permission issue fix (#114)
Browse files Browse the repository at this point in the history
* Android notification permission issue fix

* pod.lock file reverted

* DMAPP-112: project.pbxproj file reverted

* DMAPP-112: Extra space added

---------

Co-authored-by: Kushdeep Singh <[email protected]>
  • Loading branch information
meKushdeepSingh and Kushdeep Singh authored Oct 16, 2024
1 parent 25b56d5 commit b2c7517
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-feature android:name="android.hardware.audio.output"/>
<uses-feature android:name="android.hardware.microphone"/>
<uses-permission android:name="android.permission.POST_NOTIFICATION"/>
<queries>
<intent>
<action android:name="android.intent.action.VIEW"/>
Expand Down
32 changes: 24 additions & 8 deletions src/navigation/screens/PushNotifyScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import messaging from '@react-native-firebase/messaging';
import {useNavigation} from '@react-navigation/native';
import React from 'react';
import {Image, StyleSheet, View} from 'react-native';
import {PermissionsAndroid, Platform} from 'react-native';
import GLOBALS from 'src/Globals';
import {ToasterOptions} from 'src/components/indicators/Toaster';
import OnboardingWrapper from 'src/components/misc/OnboardingWrapper';
Expand All @@ -13,15 +14,22 @@ const PushNotifyScreen = () => {
const {toastRef} = useToaster();

const enableNotifications = async () => {
const settings = await messaging().requestPermission();
if (settings == messaging.AuthorizationStatus.AUTHORIZED) {
loadNextScreen();
} else {
toastRef.current?.showToast(
'Notifications are disabled. \nYou can enable them in your device settings.',
'',
ToasterOptions.TYPE.GRADIENT_PRIMARY,
if (Platform.OS === 'android') {
const res = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
);
if (res == PermissionsAndroid.RESULTS.GRANTED) {
loadNextScreen();
} else {
showToast();
}
} else {
const settings = await messaging().requestPermission();
if (settings == messaging.AuthorizationStatus.AUTHORIZED) {
loadNextScreen();
} else {
showToast();
}
}
};

Expand All @@ -32,6 +40,14 @@ const PushNotifyScreen = () => {
navigation.navigate(GLOBALS.SCREENS.GETSTARTED);
};

const showToast = () => {
toastRef.current?.showToast(
'Notifications are disabled. \nYou can enable them in your device settings.',
'',
ToasterOptions.TYPE.GRADIENT_PRIMARY,
);
};

return (
<OnboardingWrapper
title="Receive notifications for your preferred wallet activity."
Expand Down

0 comments on commit b2c7517

Please sign in to comment.