pusher-websocket-swift: PusherConnection delegate crash
Hi, when following the standard getting started, calling pusher.connect() crashes on line 42 in PusherConnection.swift. Specifically, the line shown here crashes.
self.delegate?.debugLog?(message: "[PUSHER DEBUG] Network reachable")
I can track it back as far as line 171 in Reachability.swift:
self.reachabilityChanged()
My code:
let pusher = Pusher(key: PusherSwift.key, options: PusherClientOptions(host: .cluster(PusherSwift.cluster)))
let channel = pusher.subscribe("session-status-1")
let _ = channel.bind(eventName: "App\\Events\\SessionStatusUpdated") {
guard let data = $0 as? [String: Any], let message = data["message"] as? String else { return }
print(message)
}
pusher.connect()
My PusherSwift.swift:
enum PusherSwift {
static var key: String {
return "xxx"
}
static var cluster: String {
return "eu"
}
}
Any idea?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 21 (19 by maintainers)
I’ve gotten round to doing what I described above, at least in terms of code. Still going to make README additions
So @ay8s, if this is vague for you - if you declare:
in your
ViewController, then initialize it in you function, it should work.Thanks for the project - just been having a play and I think it’s that the
PusherConnectionobject is taken asunownedinto thereachabilityclosure but because you’re not keeping a reference to thePusherinstance outside of theviewDidLoadfunction then the connection object gets cleaned up whereas the reachability object does not.I’m not sure what the best solution is here.
Perhaps
selfcould beweakinstead ofunowned?Or maybe it’s a question of making the expected usage clearer in the docs. In your example project I get the crash but even if you were to comment out all of the reachability code then I don’t think the Pusher interactions would work as expected seeing as the objects would be being cleaned up as soon as the view loads.
WDYT?
https://github.com/BasThomas/PusherSwiftCrash