Skip to content

Commit e5a9467

Browse files
authored
[MOO-1148] add push notification permission request support for Android API level>=33 (#73)
2 parents a2a2906 + dc4c2fe commit e5a9467

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/jsActions/mobile-resources-native/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2626
### Fixed
2727

2828
- We updated the default presentation mode for both "Take Picture" and "Take Picture Advanced" to full screen.
29+
- We have added push notification permission request support for Android API level>=33.
2930

3031
## [2.0.2] ColumnChart
3132
### Fixed

packages/jsActions/mobile-resources-native/src/notifications/RequestNotificationPermission.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// - the code between BEGIN USER CODE and END USER CODE
66
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
77
// Other code you write will be lost the next time you deploy the project.
8-
import { NativeModules, Platform } from "react-native";
8+
import { NativeModules, PermissionsAndroid, Platform } from "react-native";
99
import messaging from "@react-native-firebase/messaging";
1010

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

27+
if (Platform.OS === "android") {
28+
return PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS)
29+
.then(() => {
30+
return true;
31+
})
32+
.catch(() => {
33+
return false;
34+
});
35+
}
36+
2737
return messaging()
2838
.requestPermission()
2939
.then(() =>

0 commit comments

Comments
 (0)