Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an event for disconnecting from the internet on iOS?

I have an application that requires an internet connection for a certain library I use (XIMSS for Communigate). It receives status updates from a server and I can't alter the source of the lib. Is there a way to detect that the device disconnected from the internet? I'd like to avoid having to ping a server every x seconds to see if there is still a connection.

like image 760
Kevin Avatar asked Dec 08 '22 13:12

Kevin


2 Answers

Apple's Reachability does this for you. Notifies you as your connectivity changes.

like image 81
Rob Avatar answered Jan 20 '23 23:01

Rob


In iOS you can check like that :-

-(BOOL)returnInternetConnectionStatus{

     ReachabilityLattest *reach = [ReachabilityLattest reachabilityForInternetConnection];
     NetworkStatus internetStatus = [reach currentReachabilityStatus];
     if ((internetStatus != NotReachable)) {
           return TRUE;
     } else {
           return FALSE;
     }
}

For more detail you can download from here Reachability Sample Code

Hope this helps you !

like image 28
Arpit Kulsreshtha Avatar answered Jan 21 '23 00:01

Arpit Kulsreshtha