pusher / push-notifications-swift

Swift SDK for the Pusher Beams product:
https://www.pusher.com/beams
MIT License
34 stars 24 forks source link

Completion handler never called in `clearAllState(completion:)` #186

Open tfe opened 9 months ago

tfe commented 9 months ago

I'm calling clearAllState upon user logging out, as recommended in the docs. I've noticed that the completion handler is not being called, which at least in my current implementation results in the log-out process hanging, since it never continues past the step where I clear all Pusher state.

Is it expected that the clearAllState completion handler will sometimes (or every time in my case) not get called?

If so it would be great to call that out in the documentation so that folks don't get tripped up on this in the future like I did.

tfe commented 9 months ago

An update: I'm seeing the same behavior on calling setUserId... the completion handler is never executed.

I haven't done extensive testing but this is happening consistently in the Xcode 15 simulator.

I have to assume it's not happening on real devices, otherwise no one would be able to sign in/out of our app since we make these calls to the Pusher SDK as part of those flows.

Have you gotten any reports from other folks seeing similar behavior?

benw-pusher commented 8 months ago

The xCode Simulator doesn't support Push Notifications and so the library functionality can't be guaranteed. If you are not seeing this on live devices I would suggest the cause of the issue here is the simulator and not our library.

tfe commented 8 months ago

If that's the case, then I would suggest adding some conditions to detect the simulator environment and still call the callback the same way it would be in production. Leaving the callback silently un-called would be unexpected behavior in any circumstance, simulator or not.

Another option would be to print a warning or raise an exception (or call the callback with an error) if the callback-using methods are invoked in the simulator environment.

Or even better (and this would be a benefit on live devices as well, a built-in timeout after which the callback is called with an error.

If I got bitten by this, I'm probably not the only one. If nothing else, a note in the documentation around these methods would give folks some warning that these methods may not behave as expected in the simulator environment.

garyThrels commented 1 month ago

I am running this on a live device, using a react native project and the completion handlers for both clearAllState and setUserId are not being called