How can I check Realm Object Server is offline or online(Swift/iOS)?


#1

I got a problem , i would like to get server connect state when my device connecting the wifi ,because some time WIFI AP no internet connection or bad network , i would like to stop user to do someting.
I try to use the syncSession.connectionState,but always response “connected”.

func checkState(){
if let syncSession = syncUser?.allSessions().first{
switch syncSession.connectionState{
case .connected:
print(“connected~~~~~~~”)
case .connecting:
print(“connecting~~~~~~~”)
case .disconnected:
print(“disconnected~~!”)
view.isHidden = true
}
}
}