Check for internet connection with Swift

前端 未结 21 1562
别跟我提以往
别跟我提以往 2020-11-22 05:59

When I try to check for an internet connection on my iPhone I get a bunch of errors. Can anyone help me to fix this?

The code:

import Foundation
impo         


        
21条回答
  •  -上瘾入骨i
    2020-11-22 06:27

    struct Connectivity {
            static let sharedInstance = NetworkReachabilityManager()!
            static var isConnectedToInternet:Bool {
                return self.sharedInstance.isReachable
            }
        }
    

    Now call it

    if Connectivity.isConnectedToInternet{
                call_your_methods_here()
            }else{
                show_alert_for_noInternet()
            }
    

提交回复
热议问题