1 Reply Latest reply on Nov 28, 2013 5:32 PM by Mark Nongkhlaw

    Notified of network connection

    Dave Philips

      I was wondering of the best way to have an app be notified when it has a network connection?

       

      I currently sync data back and forth manually using AsyncHttp, as it connects to an xml web service rather than rhosync.

       

      I was wondering if there was an event in RhoMobile that fires when a network connection is available? I could then attempt to upload my data from the device to the server silently.

       

      I saw there is a Network component in RhoElements, but I am not using elements.

       

      The other idea I had was to have a timer, and periodically call a function that checks System.get_property('has_network')

       

      This could either be done via ruby:

       

      def repeat_every(seconds)
        while true do
          has_network = System.get_property('has_network')

          if !has_network

            sleep(seconds)

          else

                  # sync with web server if we have any unsync'd records

          end
        end
      end

       

      or javascript:

       

      setInterval(function(){ checkNetwork() }, 1000);

       

      function checkNetwork()

      {

        // Call ruby controller via ajax to check if we have network

      }

       

      I guess with both of these approaches, there will be a performance overhead.

       

      Any ideas would be greatly appreciated.

       

      Thanks.