Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOO-1184]: Fix request notification permission (9.24) #76

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/jsActions/mobile-resources-native/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- We fixed and issue when request notification permission for Android SDK 33.

### Changed

- Minimum mx version set to 9.24.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
import { NativeModules, Platform } from "react-native";
import { NativeModules, Platform, PermissionsAndroid } from "react-native";
import messaging from "@react-native-firebase/messaging";

// BEGIN EXTRA CODE
Expand All @@ -24,16 +24,29 @@ export async function RequestNotificationPermission(): Promise<boolean> {
return Promise.reject(new Error("Firebase module is not available in your app"));
}

return messaging()
.requestPermission()
.then(() =>
Platform.OS === "ios" && !messaging().isDeviceRegisteredForRemoteMessages
? messaging()
.registerDeviceForRemoteMessages()
.then(() => true)
: true
)
.catch(() => false);
try {
if (Platform.OS === "android") {
const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);

if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
return false;
}
} else if (Platform.OS === "ios") {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;

if (!enabled) {
if (!messaging().isDeviceRegisteredForRemoteMessages) {
await messaging().registerDeviceForRemoteMessages();
}
}
}
} catch (error) {
return false;
}
return true;

// END USER CODE
}
Loading