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

finished triggering twice when using MacCatalyst #43

Open
PedroFarina opened this issue Oct 10, 2023 · 0 comments
Open

finished triggering twice when using MacCatalyst #43

PedroFarina opened this issue Oct 10, 2023 · 0 comments

Comments

@PedroFarina
Copy link

Not entirely sure why, but when referencing a ping instance inside observer logic, when entering background via NotificationCenter, it gets triggered twice.

Error triggering example:

let pinger: SwiftyPing
let config = PingConfiguration(interval: 1, with: 5)
if IPv4Address(address) != nil {
    pinger = try .init(ipv4Address: address, config: config, queue: .global())
} else {
    pinger = try .init(host: address, configuration: config, queue: .global())
}
pinger.targetCount = 3
pinger.observer = { _ in
    if false {
        pinger.haltPinging()
    }
}
pinger.finished = { (response) in 
   print("Foo")
}

Not triggering example:

let pinger: SwiftyPing
let config = PingConfiguration(interval: 1, with: 5)
if IPv4Address(address) != nil {
    pinger = try .init(ipv4Address: address, config: config, queue: .global())
} else {
    pinger = try .init(host: address, configuration: config, queue: .global())
}
pinger.targetCount = 3
pinger.observer = { _ in
    print("Yeah, no idea why")
}
pinger.finished = { (response) in 
   print("Foo")
}

From what I'm seeing in the code private func addAppStateNotifications() { does have a #if os(iOS) so I'll open a PR adding to that with a && !targetEnvironment(macCatalyst) which should do the trick as I'm assuming there's no need to halt pinging when moving to background on Mac, but it doesn't quite explain why the heck capturing a reference to the ping instance even when never using it makes it trigger twice.

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

1 participant