aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.39k stars 2.11k forks source link

Notifications.Push.onNotificationReceivedInBackground is not a function. #11388

Closed aalindQuantel closed 1 year ago

aalindQuantel commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Push Notifications

Amplify Categories

notifications

Environment information

``` # Put output below this line System: OS: macOS 12.0.1 CPU: (8) x64 Apple M1 Memory: 19.06 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.4 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.8 - /opt/homebrew/bin/npm Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman Browsers: Chrome: 113.0.5672.126 Edge: 113.0.1774.35 Safari: 15.1 npmPackages: @aws-amplify/rtn-push-notification: ^1.1.1 => 1.1.1 @babel/core: ^7.12.9 => 7.21.8 @babel/runtime: ^7.12.5 => 7.21.5 @codler/react-native-keyboard-aware-scroll-view: ^2.0.1 => 2.0.1 (1.0.1) @highcharts/highcharts-react-native: ^2.2.1 => 2.2.3 @react-native-async-storage/async-storage: ^1.17.3 => 1.18.1 @react-native-community/blur: ^4.2.0 => 4.3.2 @react-native-community/clipboard: ^1.5.1 => 1.5.1 @react-native-community/eslint-config: ^2.0.0 => 2.0.0 @react-native-community/netinfo: ^8.2.0 => 8.3.1 @react-native-community/picker: ^1.8.1 => 1.8.1 @react-native-community/push-notification-ios: ^1.10.1 => 1.11.0 @react-native-cookies/cookies: ^6.2.1 => 6.2.1 @react-navigation/bottom-tabs: ^6.3.1 => 6.5.7 @react-navigation/material-top-tabs: ^6.2.1 => 6.6.2 @react-navigation/native: ^6.0.10 => 6.1.6 @react-navigation/native-stack: ^6.6.2 => 6.9.12 @react-navigation/stack: ^6.2.1 => 6.3.16 @redux-devtools/extension: ^3.2.2 => 3.2.5 @rematch/core: ^2.2.0 => 2.2.0 @rematch/persist: ^2.1.2 => 2.1.2 @rematch/select: ^3.1.2 => 3.1.2 @twotalltotems/react-native-otp-input: ^1.3.11 => 1.3.11 @wwdrew/react-native-numeric-textinput: ^1.1.0 => 1.1.0 HelloWorld: 0.0.1 accounting: ^0.4.1 => 0.4.1 amazon-cognito-identity-js: ^5.2.8 => 5.2.14 (6.2.0) aws-amplify: ^5.2.1 => 5.2.1 babel-jest: ^26.6.3 => 26.6.3 chart.js: ^3.7.1 => 3.9.1 chart.js-auto: undefined () chart.js-helpers: undefined () code-push: ^4.0.5 => 4.1.2 eslint: ^7.32.0 => 7.32.0 example: 0.0.1 formik: ^2.2.9 => 2.2.9 galio-framework: ^0.8.0 => 0.8.0 hermes-inspector-msggen: 1.0.0 jest: ^26.6.3 => 26.6.3 jwt-encode: ^1.0.1 => 1.0.1 lodash: ^4.17.21 => 4.17.21 (4.17.4, 3.10.1) lottie-ios: ^3.2.3 => 3.5.0 lottie-react-native: ^5.0.1 => 5.1.6 metro-react-native-babel-preset: ^0.67.0 => 0.67.0 moment: ^2.29.3 => 2.29.4 native-base: ^2.15.2 => 2.15.2 parse-google-address: ^1.0.4 => 1.0.4 pubnub: ^5.0.1 => 5.0.1 pubnub-react: ^2.1.1 => 2.1.1 react: 17.0.2 => 17.0.2 (0.14.10) react-devtools-core: ^4.24.4 => 4.27.7 react-native: ^0.68.5 => 0.68.7 react-native-auto-scrolling: ^3.0.2 => 3.0.2 react-native-autoheight-webview: ^1.6.1 => 1.6.5 react-native-biometrics: ^2.1.4 => 2.2.2 react-native-chonse-select: ^1.0.5 => 1.0.5 react-native-code-push: ^7.0.4 => 7.1.0 react-native-confirmation-code-field: ^7.3.0 => 7.3.1 react-native-country-code-list: ^1.1.2 => 1.1.2 react-native-date-picker: ^4.2.5 => 4.2.13 react-native-device-info: ^8.7.1 => 8.7.1 react-native-dialog: ^9.2.1 => 9.3.0 react-native-dynamic-search-bar: ^2.0.2 => 2.0.2 react-native-easy-toast: ^2.0.0 => 2.3.0 react-native-elements: ^3.4.2 => 3.4.3 react-native-fingerprint-scanner: ^6.0.0 => 6.0.0 react-native-flash-message: ^0.2.1 => 0.2.1 react-native-gesture-handler: ^2.9.0 => 2.10.1 react-native-get-random-values: ^1.9.0 => 1.9.0 react-native-hide-show-password-input: ^1.2.0 => 1.2.0 react-native-inappbrowser-reborn: ^3.6.3 => 3.7.0 react-native-keychain: ^8.1.1 => 8.1.1 react-native-linear-gradient: ^2.5.6 => 2.6.2 react-native-mask-input: ^1.2.2 => 1.2.3 react-native-masked-text: ^1.13.0 => 1.13.0 react-native-modal: ^13.0.1 => 13.0.1 react-native-otp-textinput: 0.0.8 => 0.0.8 react-native-pager-view: ^5.4.15 => 5.4.25 react-native-paper: ^4.12.0 => 4.12.5 react-native-parallax-scroll-view: ^0.21.3 => 0.21.3 react-native-permissions: ^3.8.0 => 3.8.0 react-native-phone-input: ^1.3.3 => 1.3.6 react-native-phone-number-input: ^2.1.0 => 2.1.0 react-native-picker-select: ^8.0.4 => 8.0.4 react-native-pixel-perfect: ^1.0.2 => 1.0.2 react-native-plaid-link-sdk: ^10.3.0 => 10.3.0 react-native-push-notification: ^8.1.1 => 8.1.1 react-native-radio-buttons-group: ^2.2.10 => 2.3.2 react-native-reanimated: ^2.9.1 => 2.17.0 react-native-redash: ^16.2.3 => 16.3.0 (12.6.1) react-native-remote-svg: ^2.0.7 => 2.0.11 react-native-render-html: ^6.3.4 => 6.3.4 react-native-safe-area-context: ^4.2.4 => 4.5.3 react-native-screens: ^3.14.0 => 3.20.0 react-native-scrollable-tab-view: ^1.0.0 => 1.0.0 react-native-searchable-dropdown: ^1.1.3 => 1.1.3 react-native-select-two: ^1.1.0 => 1.1.0 react-native-shimmer: ^0.6.0 => 0.6.0 react-native-simple-toast: ^1.1.3 => 1.1.4 react-native-slider: ^0.11.0 => 0.11.0 react-native-speedometer: ^1.0.5 => 1.0.5 react-native-speedometer-chart: ^0.7.5 => 0.7.5 react-native-spinkit: ^1.5.1 => 1.5.1 react-native-splash-screen: ^3.3.0 => 3.3.0 react-native-step-indicator: ^1.0.3 => 1.0.3 react-native-svg: ^12.3.0 => 12.5.1 react-native-svg-charts: ^5.4.0 => 5.4.0 react-native-swiper: ^1.6.0 => 1.6.0 react-native-tab-view: ^3.1.1 => 3.5.1 react-native-table-component: ^1.2.2 => 1.2.2 react-native-ticker: ^5.0.1 => 5.1.0 react-native-touch-id: ^4.4.1 => 4.4.1 react-native-ui-lib: ^6.13.3 => 6.31.0 react-native-url-polyfill: ^1.3.0 => 1.3.0 react-native-vector-icons: ^9.1.0 => 9.2.0 (7.1.0) react-native-webview: ^12.0.2 => 12.0.2 react-redux: ^8.0.1 => 8.0.5 react-sortable-table: ^1.4.0 => 1.4.0 react-sortable-table-example: 1.0.0 react-test-renderer: 17.0.2 => 17.0.2 reanimated-bottom-sheet: ^1.0.0-alpha.22 => 1.0.0-alpha.22 redux: ^4.2.0 => 4.2.1 redux-persist: ^6.0.0 => 6.0.0 redux-persist/integration/react: undefined () rn-wave-bottom-bar: ^2.1.3 => 2.2.36 socket.io-client: ^4.4.1 => 4.6.1 (4.4.0) src: undefined () uilib-native: 3.0.9 use-deep-compare-effect: ^1.8.1 => 1.8.1 yup: ^0.32.11 => 0.32.11 npmGlobalPackages: expo-cli: 6.1.0 npm: 6.14.8 react-devtools: 4.26.0 ```

Describe the bug

I have migrated from my previous push notification library to the latest one, specifically from "aws-amplify": "^4.3.32" to "aws-amplify": "^5.2.1" and from "@aws-amplify/pushnotification": "^4.3.29" to "@aws-amplify/rtn-push-notification": "^1.1.1". I followed the instructions provided in the documentation "https://docs.amplify.aws/lib/push-notifications/migrate-from-previous-version/q/platform/react-native/". Overall, the migration process went smoothly, especially regarding authentication. However, I'm encountering an issue when using certain functions related to notifications, such as Notifications.Push.onNotificationReceivedInBackground or Notifications.Push.enable(). These functions seem to be unrecognized. I've attempted to resolve the problem by removing the node modules and package.lock files, and then reinstalling everything, but unfortunately, there has been no improvement.

Screen Shot 2023-05-19 at 12 54 31

Expected behavior

ideally functions like Notifications.Push.getPermissionStatus() and other should work in order to get pushnotifications

Reproduction steps

install "aws-amplify": "^4.3.32" and "@aws-amplify/pushnotification": "^4.3.29" try upgrading to "aws-amplify": "^5.2.1" and "@aws-amplify/rtn-push-notification" follow migration steps given in https://docs.amplify.aws/lib/push-notifications/migrate-from-previous-version/q/platform/react-native/

Code Snippet

// Put your code below this line.
Index.js 

import 'react-native-gesture-handler';
import 'react-native-get-random-values';
import 'react-native-url-polyfill/auto';

import {AppRegistry} from 'react-native';
import {Amplify, Notifications} from 'aws-amplify';

import App from './App';
import {name as appName} from './app.json';

import config from './aws-exports-prod';

Amplify.configure({
  ...config,
  API: {
    endpoints: [
      {
        name: 'plaidservices',
        endpoint: 'https://------',
      },
      {
        name: 'streaming',
        endpoint: 'https://------',
      },
    ],
  },
});
// Notifications.Push.enable();

AppRegistry.registerComponent(appName, () => App);

Log output

``` // Put your logs below this line TypeError: _$$_REQUIRE(_dependencyMap[19], "aws-amplify").Notifications.Push.onNotificationReceivedInBackground is not a function. (In '_$$_REQUIRE(_dependencyMap[19], "aws-amplify").Notifications.Push.onNotificationReceivedInBackground(console.log('in app notification'))', '_$$_REQUIRE(_dependencyMap[19], "aws-amplify").Notifications.Push.onNotificationReceivedInBackground' is undefined) ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

android emulator

Mobile Operating System

android 13

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

cwomack commented 1 year ago

Related to #11338

aalindQuantel commented 1 year ago

@cwomack no it’s a completely different issue in android devices i am not able to use pushnotifications as no function is running related to Notifications prop

cwomack commented 1 year ago

Thanks for the clarity @aalindQuantel, just saw your comment on the other issue before I got a chance to diver deeper on this. I'll reply back as soon as I get a chance to review this further.

aalindQuantel commented 1 year ago

Hey this issue is resolved it was related to configuration . Just added this to aws config . Notifications: { Push: { AWSPinpoint: { appId: '<app-id>', region: '<region>' } } }

cwomack commented 1 year ago

@aalindQuantel, great to hear you were able to unblock yourself! Feel free to reply back and let us know if you experience any further issues.

dinesh-brilworks commented 5 months ago

Getting this error even after added notifications configurations,

TypeError: _$$_REQUIRE(dependencyMap[8], "aws-amplify").Notifications.Push.onNotificationReceivedInBackground is not a function. (In '$$_REQUIRE(dependencyMap[8], "aws-amplify").Notifications.Push.onNotificationReceivedInBackground(backgroundNotificationReceivedHandler)', '$$_REQUIRE(_dependencyMap[8], "aws-amplify").Notifications.Push.onNotificationReceivedInBackground' is undefined)