Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active October 2, 2016 07:24
Show Gist options
  • Save KentarouKanno/29d69da20322b4522ecd693848121553 to your computer and use it in GitHub Desktop.
Save KentarouKanno/29d69da20322b4522ecd693848121553 to your computer and use it in GitHub Desktop.
Reachability

Reachability

URL: Reachability

★ 通信チェック

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        let reachability = Reachability.reachabilityForInternetConnection()
        
        switch reachability.currentReachabilityStatus() {
        case NotReachable :
            print("通信できない")
            
        default:
            print("通信できる")
        }
    }
    
    // Same Method
    func checkHasNetworkConnection() -> Bool {
        let reachability = Reachability.reachabilityForInternetConnection()
        let networkStatus: Int = reachability.currentReachabilityStatus().rawValue
        return networkStatus != 0
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment