【问题标题】:In React Native on iOS, is there a way to determine when an app is resumed? Such as an onResume event?在 iOS 上的 React Native 中,有没有办法确定应用程序何时恢复?比如 onResume 事件?
【发布时间】:2015-11-24 23:30:22
【问题描述】:

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

【问题讨论】:

    标签: reactjs react-native


    【解决方案1】:

    希望您正在寻找这个。 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 函数中工作。
    【解决方案2】:

    这在关于AppStateIOS的文档中列出,如果还不够,可以使用send event api 阅读iOS文件夹中的AppDelegate.m,了解更多关于iOS App的生活圈。

    【讨论】:

      猜你喜欢
      • 2021-10-22
      • 2021-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-19
      • 1970-01-01
      相关资源
      最近更新 更多