简体   繁体   English

单击推送通知时,React本机应用程序进入后台

[英]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>
    );
  }

}

for more info this 更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当应用程序在后台并单击通知时,Android react-native-push-notification onNotification 没有被调用? - Android react-native-push-notification onNotification not called when app is in the background and notification clicked? 单击通知后在后台运行应用程序时,Android推送不会触发 - Android push does not trigger when app in background after notification clicked 只有当应用程序在后台时,React Native 才会接收远程推送通知 - React Native receive remote push notification only if app is in background 当应用在后台时推送通知 - Push notification when app is in background 当用户终止/杀死应用程序反应本机时发送推送通知 - Sending push notification when user terminates/kill app react native 通过在后台运行的推送通知对本机做出反应 - react native with push notification run in background 当应用程序 React Native 发生变化时的后台通知 - Background Notification when something changes with an app React Native React Native AppCenter Push-应用程序在后台时的通知 - React Native AppCenter Push - Notifications when app is in background Xamarin- MainActivity.OnNewIntent 在单击时应用程序处于后台时使用错误的参数调用推送通知 - Xamarin- MainActivity.OnNewIntent called with wrong parameters for Push Notification when App is in Background when Clicked 当应用程序进入后台时,通知显示来自上一个通知的内容 - The notification display content from the previous notification when app goes in background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM