一个非常简单的 ping 接口,用于 ping 域名或地址,用 swift 3.0 编写。该模块使用 SimplePing。
*要使用 swift 2.2 版本,请选择标有 PlainPing 0.2.2 的源或 pod.*
要运行示例项目,首先克隆仓库,然后在 Example 目录中运行 pod install
。
PlainPing 中有一个类函数,调用 PlainPing.ping(hostname, completionBlock)
。
示例
PlainPing.ping("www.google.com", withTimeout: 1.0, completionBlock: { (timeElapsed:Double?, error:Error?) in
if let latency = timeElapsed {
self.pingResultLabel.text = "latency (ms): \(latency)"
}
if let error = error {
print("error: \(error.localizedDescription)")
}
})
参数
hostName
: 使用名称或 IP 地址completionBlock
: 将返回 ms 中的耗时和错误,如果有withTimeout
: (可选),定义我们等待回答的秒数,默认 3 秒最低要求未知。已与以下版本进行测试
PlainPing 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "PlainPing"
Jonas Schoch, [email protected]
PlainPing 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。