在 iOS 上的 React Native 中,有没有办法确定应用程序何时恢复?比如 onResume 事件? [英] In React Native on iOS, is there a way to determine when an app is resumed? Such as an onResume event?

查看:41
本文介绍了在 iOS 上的 React Native 中,有没有办法确定应用程序何时恢复?比如 onResume 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to determine when an app is resumed. For instance, when you open the app, press the home button on the device, and then go back into the app.

推荐答案

希望你正在寻找这个.文档在这里

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>
 );
},

这篇关于在 iOS 上的 React Native 中,有没有办法确定应用程序何时恢复?比如 onResume 事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆