Reactjs 在iOS上的React Native中,是否有方法确定应用程序何时恢复?例如onResume事件?

Reactjs 在iOS上的React Native中,是否有方法确定应用程序何时恢复?例如onResume事件?,reactjs,react-native,Reactjs,React Native,我正在尝试确定应用程序何时恢复。例如,当您打开应用程序时,按设备上的home(主页)按钮,然后返回应用程序。希望您正在查找此应用程序。 getInitialState:function(){ 返回{ currentAppState:AppStateIOS.currentState, }; }, componentDidMount:function(){ AppStateIOS.addEventListener('change',this.\u handleAppStateChange); },

我正在尝试确定应用程序何时恢复。例如,当您打开应用程序时,按设备上的home(主页)按钮,然后返回应用程序。

希望您正在查找此应用程序。

getInitialState:function(){
返回{
currentAppState:AppStateIOS.currentState,
};
},
componentDidMount:function(){
AppStateIOS.addEventListener('change',this.\u handleAppStateChange);
},
componentWillUnmount:function(){
AppStateIOS.removeEventListener('change',this.\u handleAppStateChange);
},
_handleAppStateChange:函数(currentAppState){
this.setState({currentAppState,});
},
render:function(){
返回(
当前状态为:{this.state.currentAppState}
);
},

这是关于AppStateIOS的文档中列出的,如果这还不够,您可以使用iOS文件夹中的read the AppDelegate.m,您可以了解更多有关iOS应用程序的生命周期。

哇,我怎么会错过这一点。非常感谢你!谢谢顺便说一句,现在最好使用
AppState
而不是
AppStateIOS
。我必须使用
this.\u handlappstatechange.bind(this)
使
this
\u handlappstatechange
函数中工作。
getInitialState: function() {
  return {
    currentAppState: AppStateIOS.currentState,
  };
},
componentDidMount: function() {
  AppStateIOS.addEventListener('change', this._handleAppStateChange);
},
componentWillUnmount: function() {
    AppStateIOS.removeEventListener('change', this._handleAppStateChange);
},
_handleAppStateChange: function(currentAppState) {
  this.setState({ currentAppState, });
},
render: function() {
  return (
     <Text>Current state is: {this.state.currentAppState}</Text>
 );
},