J'ai ajouté le code suivant à la viewDidLoad de mon contrôleur de vue:IOS Reachibility dans l'application entière et juste sur le point de vue charge
let reachability: Reachability
do {
reachability = try Reachability.reachabilityForInternetConnection()
} catch {
print("Unable to create Reachability")
return
}
reachability.whenReachable = { reachability in
// this is called on a background thread, but UI updates must
// be on the main thread, like this:
dispatch_async(dispatch_get_main_queue()) {
if reachability.isReachableViaWiFi() {
print("Reachable via WiFi")
} else {
print("Reachable via Cellular")
}
}
}
reachability.whenUnreachable = { reachability in
// this is called on a background thread, but UI updates must
// be on the main thread, like this:
dispatch_async(dispatch_get_main_queue()) {
print("Not reachable")
}
}
do {
try reachability.startNotifier()
} catch {
print("Unable to start notifier")
}
Il m'en informer, lorsque la vue des charges mais pas lorsque l'état changements après la charge. Je me demande comment étendre ceci afin que je puisse avoir une notification n'importe où dans l'application et pas seulement quand la vue se charge car Internet peut revenir après le chargement d'une vue.
Merci
Ai-je tort ou comment pouvez-vous déclarer une constante avec son type mais sans la valeur? –