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.42k stars 2.12k forks source link

PushNotification.initializeAndroid: Get the token from Firebase Service null #8950

Closed ahtokca closed 2 years ago

ahtokca commented 2 years 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 11.5.2 CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 5.87 GB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.5 - /usr/local/bin/node npm: 6.14.11 - /usr/local/bin/npm Watchman: 2021.08.23.00 - /usr/local/bin/watchman Browsers: Chrome: 93.0.4577.82 Firefox: 92.0 Safari: 14.1.2 npmPackages: @apollo/client: ^3.4.8 => 3.4.8 @apollo/client/cache: undefined () @apollo/client/core: undefined () @apollo/client/errors: undefined () @apollo/client/link/batch: undefined () @apollo/client/link/batch-http: undefined () @apollo/client/link/context: undefined () @apollo/client/link/core: undefined () @apollo/client/link/error: undefined () @apollo/client/link/http: undefined () @apollo/client/link/persisted-queries: undefined () @apollo/client/link/retry: undefined () @apollo/client/link/schema: undefined () @apollo/client/link/utils: undefined () @apollo/client/link/ws: undefined () @apollo/client/react: undefined () @apollo/client/react/components: undefined () @apollo/client/react/context: undefined () @apollo/client/react/data: undefined () @apollo/client/react/hoc: undefined () @apollo/client/react/hooks: undefined () @apollo/client/react/parser: undefined () @apollo/client/react/ssr: undefined () @apollo/client/testing: undefined () @apollo/client/utilities: undefined () @aws-amplify/analytics: ^4.0.2 => 4.0.2 @aws-amplify/api: ^3.2.14 => 3.2.14 @aws-amplify/auth: ^3.4.14 => 3.4.14 @aws-amplify/core: ^3.8.6 => 3.8.6 @aws-amplify/pushnotification: ^3.2.14 => 3.2.14 @aws-amplify/storage: ^3.3.14 => 3.3.14 @babel/core: ^7.9.0 => 7.9.0 @babel/plugin-proposal-class-properties: ^7.13.0 => 7.13.0 @babel/preset-env: ^7.14.2 => 7.14.2 @babel/preset-react: ^7.12.10 => 7.12.10 @babel/runtime: 7.9.2 => 7.9.2 (7.12.5) @bam.tech/react-native-make: ^3.0.0 => 3.0.0 @miblanchard/react-native-slider: ^1.5.0 => 1.5.0 @react-native-async-storage/async-storage: ^1.15.5 => 1.15.5 @react-native-community/blur: ^3.6.0 => 3.6.0 @react-native-community/checkbox: ^0.4.2 => 0.4.2 @react-native-community/datetimepicker: ^3.0.9 => 3.0.9 @react-native-community/eslint-config: 0.0.5 => 0.0.5 @react-native-community/google-signin: ^4.0.0 => 4.0.0 @react-native-community/masked-view: ^0.1.11 => 0.1.11 @react-native-community/netinfo: ^6.0.0 => 6.0.0 @react-native-community/push-notification-ios: ^1.7.3 => 1.7.3 (1.0.3) @react-native-firebase/analytics: ^7.6.10 => 7.6.10 @react-native-firebase/app: ^8.4.7 => 8.4.7 @react-native-firebase/crashlytics: ^8.5.2 => 8.5.2 @types/jest: ^26.0.23 => 26.0.23 @types/react-native: ^0.63.43 => 0.63.43 @types/react-native-navigation: ^2.0.0 => 2.0.0 @types/react-native-video: ^5.0.5 => 5.0.5 @types/react-redux: ^7.1.15 => 7.1.15 @types/react-test-renderer: ^17.0.1 => 17.0.1 @typescript-eslint/eslint-plugin: ^4.31.1 => 4.31.1 (1.13.0) @typescript-eslint/parser: ^4.31.1 => 4.31.1 (1.13.0) HelloWorld: 0.0.1 amazon-cognito-auth-js: ^1.3.3 => 1.3.3 amazon-cognito-identity-js: ^4.5.12 => 4.5.12 (4.5.5) apollo-boost: ^0.4.7 => 0.4.7 aws-amplify: ^3.3.11 => 3.3.11 aws-amplify-react: ^4.2.15 => 4.2.15 aws-amplify-react-native: ^4.2.9 => 4.2.9 aws-appsync: ^4.0.3 => 4.0.3 aws-sdk: ^2.868.0 => 2.868.0 babel-eslint: ^10.1.0 => 10.1.0 (10.0.1) babel-jest: ^24.9.0 => 24.9.0 babel-plugin-module-resolver: ^4.1.0 => 4.1.0 base64-arraybuffer: ^0.2.0 => 0.2.0 buffer: ^5.6.0 => 5.6.0 (4.9.1, 4.9.2) compress-json: ^1.0.4 => 1.0.4 contentful: ^8.4.2 => 8.4.2 core-js: ^3.16.2 => 3.16.2 (2.6.12, 1.2.7) enzyme: ^3.11.0 => 3.11.0 enzyme-adapter-react-16: ^1.15.5 => 1.15.5 enzyme-to-json: ^3.6.1 => 3.6.1 es6-promise: ^4.2.8 => 4.2.8 eslint: ^7.32.0 => 7.32.0 eslint-config-airbnb: ^18.2.1 => 18.2.1 eslint-config-airbnb-typescript: ^12.3.1 => 12.3.1 eslint-config-prettier: ^6.15.0 => 6.15.0 eslint-formatter-gitlab: ^2.1.0 => 2.1.0 eslint-import-resolver-babel-module: ^5.3.1 => 5.3.1 eslint-plugin-import: ^2.23.2 => 2.23.2 eslint-plugin-jest: ^24.1.0 => 24.1.0 (22.4.1) eslint-plugin-jsx-a11y: ^6.4.1 => 6.4.1 eslint-plugin-prettier: ^4.0.0 => 4.0.0 (2.6.2) eslint-plugin-react: ^7.24.0 => 7.24.0 (7.12.4) eslint-plugin-react-hooks: ^4.2.0 => 4.2.0 (1.7.0) eslint-plugin-react-native: ^3.11.0 => 3.11.0 (3.6.0) eslint-plugin-typescript: ^0.14.0 => 0.14.0 eslint-plugin-unused-imports: ^1.1.2 => 1.1.2 get-video-duration: ^3.0.1 => 3.0.1 graphql: ^15.5.0 => 15.5.0 (14.0.0, 0.13.0) graphql-tag: ^2.11.0 => 2.11.0 (2.12.5) hermes-inspector-msggen: 1.0.0 husky: ^4.3.0 => 4.3.0 iban: 0.0.14 => 0.0.14 import: 0.0.6 => 0.0.6 intl: ^1.2.5 => 1.2.5 isomorphic-fetch: ^3.0.0 => 3.0.0 (2.2.1) jest: ^24.9.0 => 24.9.0 jest-environment-jsdom: ^26.5.2 => 26.5.2 (24.9.0) jest-enzyme: ^7.1.2 => 7.1.2 jest-junit: ^12.0.0 => 12.0.0 jimp: ^0.8.5 => 0.8.5 jwt-decode: ^3.1.2 => 3.1.2 lottie-ios: ^3.1.8 => 3.1.8 lottie-react-native: ^3.5.0 => 3.5.0 metro-config: ^0.59.0 => 0.59.0 (0.58.0) metro-react-native-babel-preset: 0.58.0 => 0.58.0 (0.59.0) moment: ^2.27.0 => 2.27.0 opentype.js: ^1.3.3 => 1.3.3 patch-package: ^6.2.2 => 6.2.2 prettier: ^2.4.0 => 2.4.0 (1.16.4) prop-types: ^15.7.2 => 15.7.2 query-string: ^6.13.1 => 6.13.1 react: 16.11.0 => 16.11.0 react-animated: 0.1.0 react-apollo: ^3.1.5 => 3.1.5 react-dom: ^16.13.1 => 16.13.1 react-native: ^0.63.2 => 0.63.2 react-native-adjust: ^4.29.2 => 4.29.2 react-native-app-badge: ^0.1.5 => 0.1.5 react-native-background-fetch: ^4.0.2 => 4.0.2 react-native-base64: ^0.1.0 => 0.1.0 react-native-camera: ^3.43.0 => 3.43.0 react-native-cardview: ^2.0.5 => 2.0.5 react-native-contacts: ^6.0.4 => 6.0.4 react-native-device-info: ^5.6.2 => 5.6.2 react-native-email-link: ^1.10.0 => 1.10.0 react-native-exception-handler: ^2.10.8 => 2.10.8 react-native-fade-in-out: ^1.0.3 => 1.0.3 react-native-fast-image: ^8.3.4 => 8.3.4 react-native-fbsdk-next: ^4.2.0 => 4.2.0 react-native-fs: ^2.16.6 => 2.16.6 react-native-gesture-handler: ^1.7.0 => 1.7.0 react-native-get-random-values: ^1.7.0 => 1.7.0 react-native-image-crop-picker: ^0.36.2 => 0.36.2 react-native-image-picker: ^3.2.1 => 3.2.1 react-native-image-resizer: ^1.4.4 => 1.4.4 react-native-inappbrowser-reborn: ^3.6.3 => 3.6.3 react-native-keyboard-aware-scroll-view: ^0.9.3 => 0.9.3 react-native-linear-gradient: ^2.5.6 => 2.5.6 react-native-mime-types: ^2.3.0 => 2.3.0 react-native-mock-render: ^0.1.9 => 0.1.9 react-native-modal-datetime-picker: ^9.1.0 => 9.1.0 react-native-navigation: ^7.7.0 => 7.7.0 react-native-navigation-hooks: ^6.2.0 => 6.2.0 react-native-permissions: ^3.0.0 => 3.0.0 react-native-reanimated: ^2.2.0 => 2.2.0 react-native-redash: ^14.2.3 => 14.2.3 react-native-restart: 0.0.17 => 0.0.17 react-native-safe-area: ^0.5.1 => 0.5.1 react-native-select-contact: ^1.5.0 => 1.5.0 react-native-select-input-ios: ^2.0.5 => 2.0.5 react-native-sha256: ^1.4.7 => 1.4.7 react-native-share: ^3.8.0 => 3.8.0 react-native-simple-radio-button: ^2.7.4 => 2.7.4 react-native-splash-screen: ^3.2.0 => 3.2.0 react-native-status-bar-height: ^2.6.0 => 2.6.0 react-native-svg: ^12.1.1 => 12.1.1 react-native-svg-transformer: ^0.14.3 => 0.14.3 react-native-uuid: ^1.4.9 => 1.4.9 react-native-video: ^5.1.1 => 5.1.1 react-native-webview: ^11.0.0 => 11.0.0 react-redux: ^7.2.0 => 7.2.0 react-test-renderer: ^16.14.0 => 16.14.0 redux: ^4.0.5 => 4.0.5 (3.7.2) redux-mock-store: ^1.5.4 => 1.5.4 redux-saga: ^1.1.3 => 1.1.3 redux-saga-test-plan: ^4.0.1 => 4.0.1 redux-saga/effects: undefined () request-promise: ^4.2.6 => 4.2.6 rn-fetch-blob: ^0.12.0 => 0.12.0 styled-components: ^5.1.1 => 5.1.1 styled-components/macro: undefined () styled-components/native: undefined () styled-components/primitives: undefined () typescript: ^4.4.3 => 4.4.3 unsplash-js: ^6.0.0 => 6.0.0 unsplash-js-node-example: 1.0.0 unsplash-js-umd-example: 1.0.0 unsplash-js-webpack-example: 1.0.0 url-parse: ^1.4.7 => 1.4.7 (1.4.4) uuid: ^8.2.0 => 8.2.0 (3.4.0, 3.3.2) npmGlobalPackages: @aws-amplify/cli: 5.1.2 aws-cdk: 1.124.0 eslint: 7.32.0 graphqlviz: 3.1.0 ios-deploy: 1.11.4 jest: 26.6.3 mermaid-filter: 1.4.5 mocha: 8.3.2 n: 7.0.1 npm: 6.14.11 tsc: 2.0.3 tslint: 6.1.3 typescript: 4.3.5 ```

Describe the bug

RNPushNotification.getToken uses deprecated API FirebaseInstanceId.getInstance().getToken() which returns null when token is not ready. Ultimately it results into a situation when user may never get PushNotification endpoint.

See details at https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId#public-string-gettoken

See example how it is implemented by @react-native-firebase/messaging at https://github.com/invertase/react-native-firebase/blob/master/packages/messaging/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingModule.java

Expected behavior

Amplify follows guidelines of getting the token in correct way

https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId#getInstanceId()

Reproduction steps

Not sure if you even need them since, documentation clearly states that FirebaseInstanceId.getInstance().getToken(); may return null if token is not ready

  1. using real device Pixel 4a
  2. Install app (it may fail to get it here)
  3. Update Analytics.updateEndpoint(request) with you custom user id
  4. uninstall the app
  5. send notification to you user using aws console or api
  6. delete pinpoint endpoints for the user
  7. install the app - at this point it never ever gets new token for me, always reports null at the console

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

Samaritan1011001 commented 2 years ago

Hello @ahtokca, I updated the other issue with some questions that can further help.

evcodes commented 2 years ago

@ahtokca, Thank you for letting us know of this problem, @Samaritan1011001 's pull request fixes this issue.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.