* Which Category is your question related to? *
@aws-amplify/pushnotification
* What AWS Services are you utilizing? *
AWS PinPoint, Analytics
* Provide additional details e.g. code snippets *
"dependencies": {
"@aws-amplify/analytics": "^1.2.10",
"@aws-amplify/pushnotification": "^1.0.22",
"aws-amplify-react-native": "^2.1.7",
"react": "16.6.3",
"react-native": "0.58.3"
},
I followed the instructions on AWS-Amplify's page to setup push notifications on React Native IOS but I noticed that I'm not getting a token back after some debugging noticed that Notification import is doesn't have configure, onRegeister or onNotification methods
My App.js file
`import React, { Component } from "react";
import {
StyleSheet,
Text,
View,
PushNotificationIOS,
} from "react-native";
import aws_exports from "./aws-exports";
import Analytics from "@aws-amplify/analytics";
import PushNotification from "@aws-amplify/pushnotification";
// PushNotification need to work with Analytics
Analytics.configure(aws_exports);
Analytics.enable();
PushNotification.configure(aws_exports);
type Props = {};
export default class App extends Component
componentDidMount(){
console.log('PN',PushNotification);
// get the notification data when notification is received
PushNotification.onNotification(notification => {
// Note that the notification object structure is different from Android and IOS
console.log("in app notification", notification);
// required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
notification.finish(PushNotificationIOS.FetchResult.NoData);
});
// get the registration token
PushNotification.onRegister(token => {
console.log("in app registration", token);
});
// get the notification data when notification is opened
PushNotification.onNotificationOpened(notification => {
console.log("the notification is opened", notification);
});
}
render() {
return (
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF"
},
welcome: {
fontSize: 20,
textAlign: "center",
margin: 10
},
instructions: {
textAlign: "center",
color: "#333333",
marginBottom: 5
}
});
`
how about save it directly to redux ?
Hi @sourabhdadapure , did you managed to solve this? I'm having the same problem, thanks.
@viniciusfont did you put the configuration outside your component ?
@viniciusfont did you put the configuration outside your component ?
I put it in the App.js outside the App class component
The device successfully appears at Pinpoint dashboard (as a endpoint without a address), but the @amplify/push_notifications module doesn't get the FCM token to update the endpoint (neither onRegister is called)
import React from 'react'
import Amplify, { Auth, Analytics } from 'aws-amplify'
import PushNotification from '@aws-amplify/pushnotification'
import awsmobile from './aws-exports'
Amplify.configure(awsmobile)
Analytics.configure(awsmobile)
PushNotification.configure(awsmobile)
// get the notification data when notification is received
PushNotification.onNotification(notification => {
// Note that the notification object structure is different from Android and IOS
console.log('in app notification', notification)
})
// get the registration token
PushNotification.onRegister(token => {
console.log('in app registration', token);
})
// get the notification data when notification is opened
PushNotification.onNotificationOpened(notification => {
console.log('the notification is opened', notification);
})
class App extends React.Component {
constructor(props) {
super(props)
}
...
}
Hi @sourabhdadapure , did you managed to solve this? I'm having the same problem, thanks.
Hi @sourabhdadapure , did you managed to solve this? I'm having the same problem, thanks.
How you solved then?
@viniciusfont
I'm not working on this anymore
I have the same problem! onRerister method is never triggered. Any updates about this issue?
Why this issue was closed if it's not solved?
onRegister() method calls once only, when the app/device is completely new.
You can read your device token from AsyncStorage.
import aws_export from 'aws_export'
AsyncStorage.getItem('push_token' + aws_export.aws_mobile_analytics_app_id)
But onRegister() is not called even once. If I inspect the Storage, there's no token
onRegister() in Android is never called, I can also confirm that.
after upgrading firebase dependencies in 'android/app/build.gradle' I had the same issue.
I found the answer here - https://github.com/aws-amplify/amplify-js/pull/2916/files#diff-1d2098d70f6a43d881eee25b70f91adb
I update "@aws-amplify/pushnotification" and got the token so -
import { NativeModules } from 'react-native';
NativeModules.RNPushNotification.getToken(token => console.log(token))
I'm facing the same issue.
Following @kolosov507 answer, I'm now able to retrieve the token 馃憤
I update "@aws-amplify/pushnotification" and got the token so -
import { NativeModules } from 'react-native';
NativeModules.RNPushNotification.getToken(token => console.log(token))
Thanks.
after upgrading firebase dependencies in 'android/app/build.gradle' I had the same issue.
I found the answer here - https://github.com/aws-amplify/amplify-js/pull/2916/files#diff-1d2098d70f6a43d881eee25b70f91adbI update "@aws-amplify/pushnotification" and got the token so -
import { NativeModules } from 'react-native';
NativeModules.RNPushNotification.getToken(token => console.log(token))
It worked for me.
Project Saver.
Most helpful comment
after upgrading firebase dependencies in 'android/app/build.gradle' I had the same issue.
I found the answer here - https://github.com/aws-amplify/amplify-js/pull/2916/files#diff-1d2098d70f6a43d881eee25b70f91adb
I update "@aws-amplify/pushnotification" and got the token so -
import { NativeModules } from 'react-native';NativeModules.RNPushNotification.getToken(token => console.log(token))