Swift-terminal network connection status, connection type (3G or WiFi)

Source: Internet
Author: User

Ijreachability is a third-party network detection class that is written using Swift. You can test whether the network is connected and support 3G and WiFi detection.

Use the sample:

1234567891011121314151617181920212223242526272829303132333435 import UIKitclass ViewController: UIViewController {        @IBOutlet weak var statusLabel: UILabel!        @IBOutlet weak var typeLabel: UILabel!            override func viewDidLoad() {        super.viewDidLoad()    }            @IBAction func checkConnect(sender: AnyObject) {        //判断连接状态        if IJReachability.isConnectedToNetwork(){            statusLabel.text = "网络连接:可用"        }else{            statusLabel.text = "网络连接:不可用"        }                //判断连接类型        let statusType = IJReachability.isConnectedToNetworkOfType()        switch statusType{            case .WWAN:                typeLabel.text = "连接类型:移动网络"            case .WiFi:                typeLabel.text = "连接类型:WiFi"            case .NotConnected:                typeLabel.text = "连接类型:没有网络连接"        }    }        override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()    }}


---ijreachability.swift---

1 ddd

Swift-terminal network connection status, connection type (3G or WiFi)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.