Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native background process

I am trying to figure out how to run background service in react native (Android). Is it possible to run code (e.g. socket listener) while app is running in background or not. I created something simple to determine that, but seems like it's not working that way. Any help?

    class HolaProject extends React.Component {

    constructor(props) {
      super(props);
      this.state = {holaText: "0"};
      var self = this;

      setTimeout(() => {
        self.setState({holaText: "after 10 seconds, works!"})
      }, 10000);
    }

    render() {
      return (
        <DrawerLayoutAndroid renderNavigationView={() => <Text>React Native</Text>}>
        <Text>{this.state.holaText}</Text>
        <ProgressBarAndroid />
      </DrawerLayoutAndroid>
    );
  }
};
like image 321
Haris Bašić Avatar asked Dec 19 '15 11:12

Haris Bašić


1 Answers

On Android

Yes, it can be done. Check this link for more information. Basically, you have to enable a notification to "wake" the device when receiving information.

On iOS

Yes, it can be done too, but through hacks. Check these links on SO to have a deeper understanding of these hacks

Play a silent sound and set the background mode to audio. Check this answer for more information on the matter.

Use VoIP services. Check more here but it'll require you justify a VoIP service to Apple.

like image 188
G. Hamaide Avatar answered Sep 23 '22 03:09

G. Hamaide