Open SwhiteMHC opened 2 weeks ago
Hello, @SwhiteMHC. I've got a couple of suggestions to see if we can unblock you here and determine the root cause.
Can you see if moving your token logic to as early in the init
process as possible changes the behavior? The token handler should be under just under the initializePushNotifications()
call ideally.
Also, the listener.remove()
call should be done within the useEffect()
hook I believe, otherwise it's being called immediately. Can you see if making this change also helps?
Hi @cwomack That worked in the minimally reproducible example. However, I recreated this example app because of an issue with another application. Making this change in the other application does not solve the problem. I have been digging into the code and observe this:
Interesting enough. I can take the token from the onHostResume() and test the push notification using Amazon Pinpoint Test Messaging, and the device successfully receives the notification.
{
"name": "com.mhc.appropos",
"version": "1.9.1",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"test": "jest --verbose && yarn ts-node scripts/regression-ms.ts",
"build:ios": "react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios'",
"build:android": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && yarn clean:drawable",
"clean:drawable": "rm -rf ./android/app/src/main/res/drawable-* && rm -rf ./android/app/src/main/res/raw",
"postinstall": "yarn run build:ios && yarn run build:android",
"browser:ios": "cd browserstack/ios && browserstack-node-sdk node test.js --env-file ../../.env",
"browser:android": "cd browserstack/android && browserstack-node-sdk node test.js --env-file ../../.env"
},
"dependencies": {
"@apollo/client": "3.8.6",
"@aws-amplify/react-native": "^1.0.28",
"@aws-amplify/rtn-push-notification": "1.2.5",
"@aws-amplify/ui-react-native": "2.0.3",
"@aws-sdk/client-scheduler": "^3.552.0",
"@expo/metro-config": "^0.10.7",
"@expo/ngrok": "4.1.0",
"@jest/globals": "29.7.0",
"@managedhealth/bac-rn-module": "^1.0.1",
"@react-native-async-storage/async-storage": "1.18.2",
"@react-native-community/netinfo": "9.3.10",
"@react-native-community/slider": "4.4.2",
"@react-native-picker/picker": "2.4.10",
"@react-navigation/native": "6.1.7",
"@react-navigation/native-stack": "6.9.13",
"@testing-library/react": "14.0.0",
"@testing-library/react-hooks": "8.0.1",
"@types/cli-progress": "^3.11.5",
"@types/jest": "29.5.5",
"@types/node": "^20.11.19",
"@types/react-native-calendar-picker": "7.0.4",
"@types/react-native-vector-icons": "6.4.15",
"apollo-upload-client": "17.0.0",
"aws-amplify": "6.0.28",
"browserstack-node-sdk": "^1.32.0",
"cli-progress": "^3.12.0",
"clsx": "2.0.0",
"dotenv": "^16.4.5",
"expo": "~49.0.15",
"expo-constants": "14.4.2",
"expo-dev-client": "~2.4.13",
"expo-file-system": "~15.4.5",
"expo-image-manipulator": "~11.3.0",
"expo-local-authentication": "~13.4.1",
"expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0",
"graphql": "16.8.1",
"haversine": "1.1.1",
"mobx": "6.10.2",
"mobx-react-lite": "4.0.4",
"mocha": "^10.3.0",
"moment": "2.29.4",
"nativewind": "2.0.11",
"react": "18.2.0",
"react-hook-form": "7.47.0",
"react-native": "0.72.10",
"react-native-blob-util": "^0.19.6",
"react-native-calendar-picker": "7.1.4",
"react-native-device-info": "^10.12.0",
"react-native-dotenv": "3.4.9",
"react-native-encrypted-storage": "4.0.3",
"react-native-geocoding": "0.5.0",
"react-native-geolocation-service": "5.3.1",
"react-native-get-random-values": "~1.9.0",
"react-native-keychain": "8.1.2",
"react-native-maps": "1.7.1",
"react-native-pdf": "^6.7.4",
"react-native-permissions": "^4.0.1",
"react-native-safe-area-context": "4.6.3",
"react-native-screens": "~3.22.0",
"react-native-uuid": "2.0.1",
"react-native-vector-icons": "10.0.0",
"react-native-vision-camera": "3.1.0",
"selenium-webdriver": "4.10.0",
"util": "0.12.5",
"webdriverio": "^8.33.1",
"xlsx": "^0.18.5"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "7.20.0",
"@faker-js/faker": "^8.4.1",
"@react-native/eslint-config": "0.72.2",
"@react-native/metro-config": "0.72.11",
"@tsconfig/react-native": "3.0.0",
"@types/apollo-upload-client": "17.0.4",
"@types/react": "^18.2.48",
"@types/react-test-renderer": "18.0.0",
"@types/xlsx": "^0.0.36",
"babel-jest": "29.2.1",
"eslint": "8.19.0",
"metro-react-native-babel-preset": "0.76.8",
"prettier": "2.4.1",
"react-test-renderer": "18.2.0",
"tailwindcss": "3.3.2",
"ts-node": "^10.9.2",
"typescript": "4.8.4"
},
"private": true,
"resolutions": {
"wrap-ansi": "7.0.0",
"string-width": "4.1.0"
}
}
Any thoughts?
@SwhiteMHC, are you using Expo Go by chance? And if I'm understanding the above comment properly, it worked in the sample app you provided to make the changes suggested? As for the other application that's experiencing this problem, are you able to share a sample repo or code that can be reviewed there as well?
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Push Notifications
Amplify Version
v6
Amplify Categories
auth, notifications
Backend
Amplify CLI
Environment information
Describe the bug
onTokenReceived event, and subsequently the handler, never fires when running on an Android Device.
Expected behavior
onTokenReceivedHandler receives new token, and token is accessible for storage and registration with Amazon Pinpoint.
Reproduction steps
I followed the setup instructions for AWS-Amplify Push Notifications for a completely new React-Native-CLI project: https://docs.amplify.aws/react-native/build-a-backend/push-notifications/set-up-push-notifications/
Minimal Reproducible Example: https://github.com/SwhiteMHC/amplify-fail-android
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
Amplify.configure({ Auth: { Cognito: { userPoolId: '', userPoolClientId: '', identityPoolId: '', }, }, Notifications: { PushNotification: { Pinpoint: { appId: '', region: '', }, }, }, Analytics: { Pinpoint: { appId: '', region: '', }, }, });
Additional configuration
Mobile Device
Galaxy A14 5G
Mobile Operating System
Android 14
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots