IJReachability是一个使用Swift写的第三方网络检测类。可以测试网络是否连接,并支持3G和Wifi的检测。
使用样例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
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 ---
1
|
ddd
|