Using Apple's reachability class in Swift

前端 未结 4 964
余生分开走
余生分开走 2020-12-08 16:33

I am rewriting my existing Objective-C code (iOS) to Swift and now am facing some issues with the Reachability class of Apple for checking network availability.

4条回答
  •  悲哀的现实
    2020-12-08 17:10

    Try below code

     let connected: Bool = Reachability.reachabilityForInternetConnection().isReachable()
    
            if connected == true {
                 println("Internet connection OK")
            }
            else
            {
                println("Internet connection FAILED")
                var alert = UIAlertView(title: "No Internet Connection", message: "Make sure your device is connected to the internet.", delegate: nil, cancelButtonTitle: "OK")
                alert.show()
            }
    

提交回复
热议问题