In React Native on iOS, is there a way to determine when an app is resumed? Such as an onResume event?

后端 未结 2 1636
旧时难觅i
旧时难觅i 2021-01-18 07:57

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.

相关标签:
2条回答
  • 2021-01-18 08:34

    this is listed on the document about AppStateIOS ,if this is not enough, you can use the send event api read the AppDelegate.m in the iOS folder , you know more the life circle about the iOS App.

    0 讨论(0)
  • 2021-01-18 08:53

    Hope you are looking for this. 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>
     );
    },
    
    0 讨论(0)
提交回复
热议问题