sourabh dadapure
sourabh dadapure

Reputation: 202

PushNotications not showing up on AWS PinPoint from @aws-amplify/pushnotification doesn't have configure, onRegeister or onNotification methods on it?

Im trying to setup PushNotiifactions on react-native IOS using AWS Amplify and PinPoint. I followed the instructions on AWS-Amplify 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 dependencies:

"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"
},

My App.js

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 (

Welcome to React Native!
To get started, edit App.js

);
}
}

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

Upvotes: 0

Views: 495

Answers (1)

Gabriela Thumé
Gabriela Thumé

Reputation: 59

Those PushNotification methods are part of its prototype, you should use something like this:

console.log('PN', Object.getOwnPropertyNames(Object.getPrototypeOf(PushNotification)))

Regarding not getting a token at onRegister, are you testing it on a real device instead of an emulator?

Upvotes: 1

Related Questions