Reachability.swift을 사용하여 인터넷 연결을 관찰 할 수 있습니다. 인터넷이 인터넷에 연결하면 인터넷을 사용할 수있는 경우이 방법이 호출됩니다
//declare this property where it won't go out of scope relative to your listener
let reachability = Reachability()!
//declare this inside of viewWillAppear
NotificationCenter.default.addObserver(self, selector: #selector(reachabilityChanged(_:)), name: .reachabilityChanged, object: reachability)
do{
try reachability.startNotifier()
}catch{
print("could not start reachability notifier")
}
서버에 모든 데이터를 업로드 할 수 있습니다 당신이 일시적으로 즉시 데이터베이스에 데이터를 저장할 수 있습니다 사용할 수없는 경우
func reachabilityChanged(note: Notification) {
let reachability = note.object as! Reachability
switch reachability.connection {
case .wifi:
print("Reachable via WiFi")
case .cellular:
print("Reachable via Cellular")
case .none:
print("Network not reachable")
}
}
호프가 문제를 해결할 수 있기를 바랍니다.