Hi Team, I’ve spent a day trying to debug this situation and I’ve read every single issue on Github related to this with no luck. I’m hoping someone can help!
So I have a simple Push Notification app with just the example code from [https://docs.expo.io/versions/latest/guides/push-notifications]
The issue is that my main App this.props.exp.notification
is non-existent when I send a push to a standalone version of the app and tap on the notification. The app is standalone using exp build:ios
and TestFlight test using SDK v26.
See post for additional details:
# app.json
{
"expo": {
...
"sdkVersion": "26.0.0",
"ios": {
"bundleIdentifier": "com.XXX.leadmanager"
},
"android": {
"package": "com.XXX.leadmanager"
}
}
# package.json:
{
"main": "node_modules/expo/AppEntry.js",
"dependencies": {
"@expo/vector-icons": "^6.2.1",
"expo": "^26.0.0",
"lodash": "^4.17.5",
"moment": "^2.20.1",
"moment-timezone": "^0.5.14",
"native-base": "^2.3.3",
"react": "16.3.0-alpha.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-26.0.0.tar.gz",
"react-navigation": "1.5.8",
"sentry-expo": "~1.7.0"
},
"devDependencies": {
"babel-plugin-module-resolver": "^3.0.0",
"enzyme": "^3.2.0",
"enzyme-adapter-react-16": "^1.1.0",
"jest-expo": "^22.0.0",
"react-addons-test-utils": "^15.6.2",
"react-dom": "^16.2.0",
"react-native-scripts": "1.7.0",
"react-test-renderer": "16.0.0-beta.5"
}
}
# My App.js:
import Expo from 'expo';
import React from 'react';
import { Alert, Text, View } from 'react-native';
import { Permissions, Notifications } from 'expo';
async function registerForPushNotificationsAsync() {
const {
status: existingStatus
} = await Permissions.getAsync(Permissions.NOTIFICATIONS);
let finalStatus = existingStatus;
if (existingStatus !== 'granted') {
const {
status
} = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
if (finalStatus !== 'granted') {
return;
}
let token = await Notifications.getExpoPushTokenAsync();
return token;
}
export default
class App extends React.Component {
state = {
notification: {},
pushToken: null,
};
async componentWillMount() {
const pushToken = await registerForPushNotificationsAsync();
this.setState({ pushToken: pushToken });
}
componentWillReceiveProps(newProps) {
Alert.alert(
'New Props',
JSON.stringify(newProps),
[ {text: 'OK', style: 'cancel'}, ],
);
}
componentDidMount() {
Notifications.addListener( (n) => this.setState({ notification: n }) );
}
render() {
const { notification, pushToken } = this.state;
return (
<View style={{ marginTop: 40 }}>
<Text
selectable={true}
style={{ fontSize: 16 }}>{pushToken}</Text>
<Text>{JSON.stringify(notification)}</Text>
<Text>{JSON.stringify(this.props)}</Text>
</View>
);
}
}
Expo.registerRootComponent(App);