question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PushNotification.onRegister not generating a token. PushNotication from @aws-amplify/pushnotification doesn't have configure, onRegeister or onNotification methods on it?

See original GitHub issue

** 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<Props> {

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 ( <View style={styles.container}> <Text style={styles.welcome}>Welcome to React Native!</Text> <Text style={styles.instructions}>To get started, edit App.js</Text> </View> ); } }

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 } }); `

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:21 (1 by maintainers)

github_iconTop GitHub Comments

29reactions
o-kolosovcommented, Aug 21, 2019

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))

9reactions
ionutmiftodecommented, Dec 31, 2021

Seems that the function changed in the latest version, so now you need to pass an error callback also

NativeModules.RNPushNotification.getToken(
  token => console.log(token),
  err => console.log(err)
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

PushNotications not showing up on AWS PinPoint from @aws ...
PushNotications not showing up on AWS PinPoint from @aws-amplify/pushnotification doesn't have configure, onRegeister or onNotification methods ...
Read more >
react-native-push-notification Code Examples - Snyk
configure ({ // (optional) Called when Token is generated (iOS and Android) onRegister: (token) => { console.log( 'TOKEN:', token ) }, // (required)...
Read more >
Getting Started with Push Notifications using AWS Amplify
The most common platforms are Apple Push Notification service (APNs), Firebase Cloud Messaging (FCM), Baidu Cloud Push, and Amazon Device ...
Read more >
Push Notifications with AWS Amplify - JavaScript Camp
onRegister ​. Each device can be recognized with a push token, with which you can specify the device for which you want to...
Read more >
react-native-push-notification - npm
Android manual Installation. NOTE: firebase-messaging , prior to version 15 requires to have the same version number in order to work correctly ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found