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 UIKit
class 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---
Swift-terminal network connection status, connection type (3G or WiFi)