samiyr/SwiftyPing

finished triggering twice when using MacCatalyst

PedroFarina opened this issue · 0 comments

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.