Reachability.swift
Reachability.swift copied to clipboard
Strong reference needed not documented
Please document the file level strong reference of the reachability object, notifier callbacks do not work if defined in viewDidLoad()
@cpellet this is already written in the docs
//declare this property where it won't go out of scope relative to your listener
let reachability = try! Reachability()
In this case allow me to suggest to make this clearer; going out of scope is not the issue here, interacting with the object in a single clause will not solve the issue as the comment suggests.
let reachability = try Reachability()
class PXX_NetWorkTypeTool : NSObject{
// static let shared = PXX_NetWorkTypeTool() // private override init() { // super.init() // }
func getNetType() -> Int {
var ClientNetType:Int = 0
reachability?.whenUnreachable = { _ in
DispatchQueue.main.async {
print("Not reachable")
ClientNetType = 1
}
}
do {
try reachability?.startNotifier()
} catch {
print("Unable to start notifier")
}
reachability?.whenReachable = { reachability in
写在工具类中,全局属性reachablity 为什么回调还是不走?