我正在使用OneSignal推送通知。
我的问题是:收到通知后如何导航到特定屏幕?我不知道该怎么办,我什至没有一个主意。
这是我的代码:
App.js:
const RootStack = createAppContainer(createStackNavigator({
ScreenOne: { screen: Screen1 },
ScreenTwo: { screen: Screen2 },
ScreenThree: { screen: ScannerQrCode },
ScreenFour: { screen: ScannerCodeBar },
ScreenFive: { screen: WebServiceUse },
ScreenSix: { screen: Cellz },
}));
export default RootStack;
class App extends Component {
constructor(props) {
super(props);
OneSignal.init("*****************");
this.state = { name: 'name' }
OneSignal.addEventListener('received', this.onReceived);
OneSignal.addEventListener('opened', this.onOpened);
OneSignal.addEventListener('ids', this.onIds);
}
componentWillUnmount() {
OneSignal.removeEventListener('received', this.onReceived);
OneSignal.removeEventListener('opened', this.onOpened);
OneSignal.removeEventListener('ids', this.onIds);
}
onReceived(notification) {
alert("Notification received: ", notification);
}
onOpened(openResult) {
alert('Message: ', openResult.notification.payload.body);
alert('Data: ', openResult.notification.payload.additionalData);
alert('isActive: ', openResult.notification.isAppInFocus);
alert('openResult: ', openResult);
}
onIds(device) {
alert('Device info: ', device);
}
}