[英]React native app goes to background when clicked on push notification
App is running in foreground. 应用正在前台运行。 Then I got push notification.
然后我得到了推送通知。 After I tapped on that push notification, My app status changes foreground to background.
在点击该推送通知后,我的应用程序状态将从前台更改为后台。 Then It comes to back to foreground.
然后,它又回到了前台。
I use OneSignal dashboard to send a sample push notification. 我使用OneSignal仪表板发送示例推送通知。 This happens in Android app.
这是在Android应用中发生的。
componentDidMount() {
// One signal notification settings
OneSignal.configure();
OneSignal.setLogLevel(5, 0); // adb logcat debug (5) logs
OneSignal.init('xxxxxxxxxxxx');
OneSignal.inFocusDisplaying(2);
OneSignal.addEventListener('ids', this.onIds);
OneSignal.getPermissionSubscriptionState((status) => {
if(status.userId)
// update userID using props
});
}
onIds = (device) => {
const userId = device.userId;
if(userId)
// update userID using props
OneSignal.removeEventListener('ids', this.onIds);
}
I couldn't find out how this happened. 我不知道这是怎么发生的。 I want to stop this app status change when I tap on a push notification.
我想在点击推送通知时停止此应用程序状态更改。 Please tell me some has any idea about this issue.
请告诉我一些关于此问题的想法。
lib versions, lib版本,
react-native-onesignal: 3.2.11
react-native: 0.57.4
react: 16.6.0-alpha.8af6728
I think you should use "AppState" to specify when to show push notification and after clicking push notification what should be "AppState". 我认为您应该使用“ AppState”来指定何时显示推送通知,并在单击推送通知后指定“ AppState”。
import React, {Component} from 'react'
import {AppState, Text} from 'react-native'
class AppStateExample extends Component {
state = {
appState: AppState.currentState
}
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
console.log('App has come to the foreground!')
}
this.setState({appState: nextAppState});
}
render() {
return (
<Text>Current state is: {this.state.appState}</Text>
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.