【发布时间】:2015-11-24 23:30:22
【问题描述】:
我正在尝试确定应用何时恢复。例如,当您打开应用程序时,按下设备上的主页按钮,然后返回应用程序。
【问题讨论】:
标签: reactjs react-native
我正在尝试确定应用何时恢复。例如,当您打开应用程序时,按下设备上的主页按钮,然后返回应用程序。
【问题讨论】:
标签: reactjs react-native
希望您正在寻找这个。 Documentation Here
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>
);
},
【讨论】:
AppState 而不是AppStateIOS。
this._handleAppStateChange.bind(this) 来代替this 才能在_handleAppStateChange 函数中工作。
这在关于AppStateIOS的文档中列出,如果还不够,可以使用send event api 阅读iOS文件夹中的AppDelegate.m,了解更多关于iOS App的生活圈。
【讨论】: