william-weng/wwnetworkmonitor
- [Integrate NWPathMonitor to detect network connections.](https://developer.apple.com/documentation/network/nwpathmonitor)
[Introduction - 簡介](https://swiftpackageindex.com/William-Weng)
[WWNetWorkMonitor]
[Installation with Swift Package Manager](https://medium.com/彼得潘的-swift-ios-app-開發問題解答集/使用-spm-安裝第三方套件-xcode-11-新功能-2c4ffcf85b4b)
dependencies: [
.package(url: "https://github.com/William-Weng/WWNetWorkMonitor.git", .upToNextMajor(from: "1.0.0"))
]可用函式
|函式|說明| |-|-| |currnetNetworkPath()|取得當前網路的相關訊息| |start(for:queue:result:)|開始監控| |cancel()|停止監控|
Example
import UIKit
import WWPrint
import WWNetWorkMonitor
final class ViewController: UIViewController {
override func viewIsAppearing(_ animated: Bool) {
super.viewIsAppearing(animated)
demo()
}
}
private extension ViewController {
func demo() {
let currentStatus = WWNetWorkMonitor.shared.currnetNetworkPath().status
wwPrint("currentStatus = \(currentStatus)")
WWNetWorkMonitor.shared.start { path in
wwPrint("use wifi [\(path.usesInterfaceType(.wifi))] => \(path.status)")
}
}
}Package Metadata
Repository: william-weng/wwnetworkmonitor
Default branch: main
README: README.md