diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 2b35a0b1e..7b418cf16 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -38,11 +38,11 @@ jobs: - name: "Defining environment variables" if: startsWith(matrix.os, 'ubuntu') id: variablesLinux - run: echo "arg=$(if [ "${{ steps.files.outputs.global_files }}" = "" ] && ${{ github.event_name == 'pull_request' }}; then echo '--since'; else echo ''; fi)" >> ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }} + run: echo "arg=$(if [ "${{ steps.files.outputs.global_files }}" = "" ] && ${{ github.event_name == 'pull_request' }}; then echo '--since'; else echo '--all'; fi)" >> ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }} - name: "Defining environment variables" if: startsWith(matrix.os, 'windows') id: variablesWindows - run: echo "arg=$(If ('${{ steps.files.outputs.global_files }}' -eq '' -AND '${{ github.event_name == 'pull_request' }}' -eq 'true'){ echo '--since' } Else { echo '' })" >> ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }} + run: echo "arg=$(If ('${{ steps.files.outputs.global_files }}' -eq '' -AND '${{ github.event_name == 'pull_request' }}' -eq 'true'){ echo '--since' } Else { echo '--all' })" >> ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }} - name: "Defining node version" uses: actions/setup-node@d86ebcd40b3cb50b156bfa44dd277faf38282d12 # v4 with: @@ -51,6 +51,6 @@ jobs: - name: "Installing dependencies" run: yarn install - name: "Running build for development" - run: yarn workspaces foreach ${{ steps.variablesLinux.outputs.arg }} ${{ steps.variablesWindows.outputs.arg }} --all --parallel run build + run: yarn workspaces foreach ${{ steps.variablesLinux.outputs.arg }} ${{ steps.variablesWindows.outputs.arg }} --parallel run build env: NODE_OPTIONS: --max_old_space_size=8192 diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index f4dd3f534..0b5226f2f 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -35,11 +35,11 @@ jobs: - name: "Defining environment variables" if: startsWith(matrix.os, 'ubuntu') id: variablesLinux - run: echo "arg=$(if [ "${{ steps.files.outputs.global_files }}" = "" ] && ${{ github.event_name == 'pull_request' }}; then echo '--since'; else echo ''; fi)" >> ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }} + run: echo "arg=$(if [ "${{ steps.files.outputs.global_files }}" = "" ] && ${{ github.event_name == 'pull_request' }}; then echo '--since'; else echo '--all'; fi)" >> ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }} - name: "Defining environment variables" if: startsWith(matrix.os, 'windows') id: variablesWindows - run: echo "arg=$(If ('${{ steps.files.outputs.global_files }}' -eq '' -AND '${{ github.event_name == 'pull_request' }}' -eq 'true'){ echo '--since' } Else { echo '' })" >> ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }} + run: echo "arg=$(If ('${{ steps.files.outputs.global_files }}' -eq '' -AND '${{ github.event_name == 'pull_request' }}' -eq 'true'){ echo '--since' } Else { echo '--all' })" >> ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }} - name: "Defining node version" uses: actions/setup-node@d86ebcd40b3cb50b156bfa44dd277faf38282d12 # v4 with: @@ -48,6 +48,6 @@ jobs: - name: "Installing dependencies" run: yarn install - name: "Running release for production" - run: yarn workspaces foreach ${{ steps.variablesLinux.outputs.arg }} ${{ steps.variablesWindows.outputs.arg }} --all --parallel run release + run: yarn workspaces foreach ${{ steps.variablesLinux.outputs.arg }} ${{ steps.variablesWindows.outputs.arg }} --parallel run release env: NODE_OPTIONS: --max_old_space_size=8192 diff --git a/.github/workflows/UnitTests.yml b/.github/workflows/UnitTests.yml index 9bf5c32f0..9b72cf308 100644 --- a/.github/workflows/UnitTests.yml +++ b/.github/workflows/UnitTests.yml @@ -31,7 +31,7 @@ jobs: run: git fetch --no-tags --prune --depth=1 origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }} - name: "Defining environment variables" id: variables - run: echo "arg=$(if [ "${{ steps.files.outputs.global_files }}" = "" ] && ${{ github.event_name == 'pull_request' }}; then echo '--since'; else echo ''; fi)" >> ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }} + run: echo "arg=$(if [ "${{ steps.files.outputs.global_files }}" = "" ] && ${{ github.event_name == 'pull_request' }}; then echo '--since'; else echo '--all'; fi)" >> ${{ runner.os == 'Windows' && '$env:GITHUB_OUTPUT' || '$GITHUB_OUTPUT' }} - name: "Defining node version" uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3 with: @@ -50,6 +50,6 @@ jobs: - name: "Installing dependencies" run: yarn install - name: "Linting code" - run: yarn workspaces foreach ${{ steps.variables.outputs.arg }} --all --parallel run lint + run: yarn workspaces foreach ${{ steps.variables.outputs.arg }} --parallel run lint - name: "Running unit tests" - run: yarn workspaces foreach ${{ steps.variables.outputs.arg }} --all --parallel run test + run: yarn workspaces foreach ${{ steps.variables.outputs.arg }} --parallel run test diff --git a/packages/jsActions/mobile-resources-native/CHANGELOG.md b/packages/jsActions/mobile-resources-native/CHANGELOG.md index 71300e977..7b93dec5a 100644 --- a/packages/jsActions/mobile-resources-native/CHANGELOG.md +++ b/packages/jsActions/mobile-resources-native/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Fixed + +- We fixed an issue where the `RequestNotificationPermission` action incorrectly returned 'true' after the user previously selected 'Don't Allow' on iOS and Android. + ## [8.0.0] Native Mobile Resources - 2024-07-30 ### BREAKING diff --git a/packages/jsActions/mobile-resources-native/src/notifications/RequestNotificationPermission.ts b/packages/jsActions/mobile-resources-native/src/notifications/RequestNotificationPermission.ts index 81074bbef..36fddaa9c 100644 --- a/packages/jsActions/mobile-resources-native/src/notifications/RequestNotificationPermission.ts +++ b/packages/jsActions/mobile-resources-native/src/notifications/RequestNotificationPermission.ts @@ -18,32 +18,40 @@ import messaging from "@react-native-firebase/messaging"; */ export async function RequestNotificationPermission(): Promise { // BEGIN USER CODE - // Documentation https://rnfirebase.io/docs/v5.x.x/notifications/receiving-notifications + // Documentation https://rnfirebase.io/messaging/usage if (NativeModules && !NativeModules.RNFBMessagingModule) { return Promise.reject(new Error("Firebase module is not available in your app")); } if (Platform.OS === "android") { - return PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS) - .then(() => { - return true; - }) - .catch(() => { - return false; - }); + try { + const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS); + return granted === PermissionsAndroid.RESULTS.GRANTED; + } catch (error) { + console.error("Failed to request permission on Android", error); + return false; + } } - return messaging() - .requestPermission() - .then(() => - Platform.OS === "ios" && !messaging().isDeviceRegisteredForRemoteMessages - ? messaging() - .registerDeviceForRemoteMessages() - .then(() => true) - : true - ) - .catch(() => false); + try { + const authStatus = await messaging().requestPermission(); + const enabled = + authStatus === messaging.AuthorizationStatus.AUTHORIZED || + authStatus === messaging.AuthorizationStatus.PROVISIONAL; + if (!enabled) { + return false; + } + + if (!messaging().isDeviceRegisteredForRemoteMessages) { + await messaging().registerDeviceForRemoteMessages(); + return true; + } + return true; + } catch (error) { + console.error("Failed to request permission on iOS", error); + return false; + } // END USER CODE }