-2

i have one app which contains many map view. And i need to check internet connect is true or false. If false one uialert message will show and uiactivity Indicator will show ( will start).... its working fine..

But when i suddenly connect the internet , that uiactivity indicator in not stoping. Still getting run.

Here my code:

override func viewDidLoad() {

    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.

    ActiviyuInc.hidden = true

    showmethod()

}



func showmethod () {



    if Reachability.isConnectedToNetwork() == false {



        print("Internet connection FAILED")

        let alert = UIAlertView(title: "No Internet Connection", message: "Make sure your device is connected to the internet.", delegate: nil, cancelButtonTitle: "OK")



        alert.show()



        if Reachability.isConnectedToNetwork() == false {

            ActiviyuInc.hidden = false

            ActiviyuInc.startAnimating()

        }

        else {

            ActiviyuInc.hidden = true

            ActiviyuInc.stopAnimating()

        }

    }



}

When my app in run, that time when i connect to internet , still my uiactivityIndicator is not stoping..

Help me out !!!

user5513630
  • 1,709
  • 8
  • 24
  • 48
  • Because you are not calling the method to check again. You do the check only once and decide to animate or stop. – erenkabakci Mar 18 '16 at 11:51
  • 2
    Please [**do not post multiple questions**](http://stackoverflow.com/questions/36081870/how-to-block-user-if-he-she-not-connected-to-internet-connection-when-my-app-l/36082625#36082625), instead update the original answer. – swiftBoy Mar 18 '16 at 11:54

2 Answers2

1

Try stopping Activity on main thread,

dispatch_async(dispatch_get_main_queue()) { () -> Void in

    ActiviyuInc.hidden = true

    ActiviyuInc.stopAnimating()
}
Bharat Modi
  • 4,158
  • 2
  • 16
  • 27
  • i tried your code, when i internet is not connect `uiactivity indicator` is starting. But when app in process ( i.e when app in running ) if i connect internet , still that `uiactivity indicator `is not stoping.... – user5513630 Mar 18 '16 at 12:10
  • How you get to know the internet connection status.(available/lost)? – Bharat Modi Mar 18 '16 at 12:13
  • I thing you want to monitor the network changes dynamically, and you want to show activity indicator if the net is not available, and hide it as soon as the network is available. – Bharat Modi Mar 18 '16 at 12:17
1

just do this.

if Reachability.isConnectedToNetwork() == false {



    print("Internet connection FAILED")

    let alert = UIAlertView(title: "No Internet Connection", message: "Make sure your device is connected to the internet.", delegate: nil, cancelButtonTitle: "OK")



    alert.show()
    ActiviyuInc.hidden = false

        ActiviyuInc.startAnimating()
} else {
 ActiviyuInc.hidden = true

 ActiviyuInc.stopAnimating()
}
Sahil
  • 9,096
  • 3
  • 25
  • 29
  • i tried your code, when i internet is not connect `uiactivity indicator` is starting. But when app in process ( i.e when app in running ) if i connect internet , still that `uiactivity indicator `is not stoping.... – user5513630 Mar 18 '16 at 12:10