J'utilise la classe d'accessibilité d'Apple dans mon code. Voici le code de la appdelegateApple Reachability ne pas afficher d'alerte
NSNotificationCenter.defaultCenter().addObserver(self, selector:"checkForReachability:", name: kReachabilityChangedNotification, object: nil);
self.reachability = Reachability.reachabilityForInternetConnection();
self.reachability.startNotifier();
et c'est checkForReachability
func checkForReachability(notification:NSNotification){
let remoteHostStatus = self.reachability!.currentReachabilityStatus()
if (remoteHostStatus.rawValue == NotReachable.rawValue) {
print("NOT REACHABLE")
let myAlert = UIAlertController(title: "Alert", message: "Please check your internet connection.", preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title:"Try again.", style:UIAlertActionStyle.Default) {
action in
self.checkForReachability(notification)
}
myAlert.addAction(okAction)
self.window?.rootViewController?.presentViewController(myAlert, animated:true, completion:nil)
}
}
Mais il ne sera pas pop l'alerte quand il n'y a pas Internet (quand j'éteins le wifi)
Obtenez-vous la déclaration d'impression (non accessible) dans la console? –
Oui je reçois –