EFInternetIndicator
要求
- Xcode 8.0+
- iOS 8.3+
警告:无法在模拟器上工作。 #1
安装
CocoaPods
您可以使用 CocoaPods 通过将其添加到您的 Podfile
来安装 EFInternetIndicator
use_frameworks!
pod 'EFInternetIndicator'
示例
要运行示例项目,请克隆仓库,然后先从示例目录运行pod install
。
使用示例
要在单个UIViewController中开始监控网络状态,只需添加InternetStatusIndicable
协议,然后使用startMonitoringInternet()
开始监控。
import UIKit
import EFInternetIndicator
class ViewController: UIViewController, InternetStatusIndicable {
var internetConnectionIndicator:InternetViewIndicator?
override func viewDidLoad() {
super.viewDidLoad()
self.startMonitoringInternet()
}
}
此外,您还可以使用自定义参数自定义指示器。
func startMonitoringInternet(backgroundColor:UIColor, style: MessageView.Layout, textColor:UIColor, message:String, remoteHostName: String)
如果要让所有你的UIViewControllers监控网络,可以创建一个抽象类,如下:
import UIKit
import EFInternetIndicator
class EFViewController: UIViewController, InternetStatusIndicable {
var internetConnectionIndicator:InternetViewIndicator?
override func viewDidLoad() {
super.viewDidLoad()
self.startMonitoringInternet()
}
}
class SecondViewController: EFViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
// Override properties when you want
class MagicViewController: EFViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.startMonitoringInternet(backgroundColor:UIColor.blue, style: .StatusLine, textColor:UIColor.white, message:"No magic on internet here :(", remoteHostName: "magic.com")
}
}
作者
ezefranca,[email protected]
致谢
- @SwiftKickMobile 致力于 SwiftMessages;
- @ashleymills 致力于 Reachability.swift;
许可
EFInternetIndicator 在MIT许可下可用。有关更多信息,请参阅LICENSE文件。