Ho incluso Reachability.h.& .m di Apple dall'esempio Reachability, oltre al framework SystemConfiguration menzionato in precedenza, quindi aggiunto il seguente codice alla mia app, che presenta due vantaggi rispetto alla risposta di cui sopra: fornisce più informazioni e ottieni notifiche asincrone delle modifiche dello stato della rete.
Nella tua app delegato, o simili, aggiungere questo quando si avvia:
[self startReachability];
Quindi aggiungere questo metodo, che viene chiamata quando la rete cambia:
#pragma mark Reachability changed
- (void)reachabilityChanged:(NSNotification*)aNote
{
self.remoteHostStatus = [[Reachability sharedReachability] remoteHostStatus];
switch (self.remoteHostStatus)
{
case NotReachable:
debugForComponent(kDebugMaskApp,@"Status changed - host not reachable");
break;
case ReachableViaCarrierDataNetwork:
debugForComponent(kDebugMaskApp,@"Status changed - host reachable via carrier");
break;
case ReachableViaWiFiNetwork:
debugForComponent(kDebugMaskApp,@"Status changed - host reachable via wifi");
break;
default:
debugForComponent(kDebugMaskApp,@"Status changed - some new network status");
break;
}
}
fonte
2009-04-24 06:43:08
Hai trovato una risposta? – JoePasq
** Passo dopo passo soluzione ** Vedere la risposta: http://stackoverflow.com/a/25498693/2459296 – Salim