Alamofire: Reachability not working correctly

Created on 15 Nov 2016  路  2Comments  路  Source: Alamofire/Alamofire

I tried to use NetworkReachabilityManager as follow in the iOS example, but it doesn't work correctly:

  1. When I just start the app, it shows:

status :reachable(Alamofire.NetworkReachabilityManager.ConnectionType.ethernetOrWiFi)
status :notReachable

  1. And I turned the airplane mode on to disconnect the internet, it didn't respond to show me the internet is off.

  2. When I turned the airplane mode, it shows

statuslala :reachable(Alamofire.NetworkReachabilityManager.ConnectionType.ethernetOrWiFi)
statuslala :notReachable
statuslala :reachable(Alamofire.NetworkReachabilityManager.ConnectionType.ethernetOrWiFi)
statuslala :notReachable

The result is not correct. Can you please figure it out what's the problem?


The testing profile is:
Xcode 8.2 beta
iPhone 6, iOS 10.1.1
The newest Alamofire commit: 928cdae0c54957cb53a6873ec64a109bc6a1be60
Under 3G internet

class MasterViewController: UITableViewController {

    @IBOutlet weak var titleImageView: UIImageView!

    let manager = NetworkReachabilityManager(host: "https://www.apple.com/")

    var detailViewController: DetailViewController? = nil
    var objects = NSMutableArray()

    override func awakeFromNib() {
        super.awakeFromNib()

        navigationItem.titleView = titleImageView

        weak var wSelf = self
        manager?.listener = {status in
            print("statuslala :\(status)")
            let alert = UIAlertController(title: "Alert", message: "status:\(status)", preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "Click", style: .default, handler: nil))
            wSelf?.present(alert, animated: true, completion: nil)
        }

        manager?.startListening()
    }
question

Most helpful comment

You need to use www.apple.com as the host. It gets all screwed up when you throw the scheme in there.

Cheers. 馃嵒

All 2 comments

You need to use www.apple.com as the host. It gets all screwed up when you throw the scheme in there.

Cheers. 馃嵒

Awesome! Problem sovled. I hope this colsed issue helpful to others...

Was this page helpful?
0 / 5 - 0 ratings