Создайте свое собственное окно для устранения условий.
import UIKit
import ReachabilitySwift
class HSWindow: UIWindow {
let sharedReachability = Reachability()!
// override point for subclass. Do not call directly
open override func becomeKey(){
sharedReachability.whenReachable = { reachability in
OperationQueue.main.addOperation({
self.removeRechabilityView()
})
}
sharedReachability.whenUnreachable = { reachability in
OperationQueue.main.addOperation({
self.addRechabilityView()
})
}
do {
try sharedReachability.startNotifier()
print("sharedReachability.startNotifier : Starting.....")
} catch {
print("sharedReachability.startNotifier : Unable to start notifier")
}
}
// override point for subclass. Do not call directly
open override func resignKey(){
sharedReachability.stopNotifier()
}
}
//add remove Rechability view
extension HSWindow {
func addRechabilityView(){
self.removeRechabilityView()
let view = HSRechabilityView(); //you any custom view that you want to show on internet connection loss
self.addSubview(view)
view.snp.makeConstraints { (make) in //instead of this you can give frame, I have used snapKit here
make.edges.equalTo(self)
}
}
func removeRechabilityView(){
for view in self.subviews { //find your view and remove when internet connected
if view is HSRechabilityView {
view.removeFromSuperview()
break;
}
}
}
}
В AppDelegate - метод didFinishLaunching
self.window = HSWindow(frame: UIScreen.main.bounds) //user your custom window instead of default one, and this will do all magic without any code
self.window.makeKeyAndVisible()
ПустьЯ знаю, если вы будете что-нибудь делать в этом потоке