Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strong reference needed not documented #363

Open
cpellet opened this issue Jun 9, 2020 · 3 comments
Open

Strong reference needed not documented #363

cpellet opened this issue Jun 9, 2020 · 3 comments

Comments

@cpellet
Copy link

cpellet commented Jun 9, 2020

Please document the file level strong reference of the reachability object, notifier callbacks do not work if defined in viewDidLoad()

@RubenVot
Copy link

@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()

@cpellet
Copy link
Author

cpellet commented Jun 24, 2020

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.

@ChinaKeep
Copy link

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 为什么回调还是不走?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants