Search code examples
iospopuptouchtouchescancelled

iOS: not getting touchesCancelled when getting a native popup


I'm not used to working on native iOS code. So excuse me for missing something obvious here.

The issue I'm having right now, is when a user is holding down a touch, and then before releasing, a native popup appears (low battery, timer, ...), this does not fire a call to touchesCancelled. Instead, it fires a touchesEnded when the user stops touching the screen.

However, this touchedEnded was a user reaction to the popup, not an active decision for using the app, and this might lead to incorrect and frustrating behaviour.

As far as I can tell, the touchesCancelled should be fired when focus is lost, but it seems focus is not completely lost in this case.

I am wondering if there is any other way to detect that a native popup was opened, and have my app act like touchesCancelled was fired, and avoid unintentional behaviour.

I've tested some apps from Apple and they have the same (in my opinion) wrong behaviour. So maybe it's something I have to live with, but I want to reach out to more experienced native iOS devs, and be sure of it.

Thanks, Sascha


Solution

  • I returned back to this issue today. I found out that when a native popup appears, there is a call into the app to applicationWillResignActive and applicationDidBecomeActive respectively.

    In my solution, at the moment applicationWillResignActive is called, I basically make the app act as if there was a touchesCancelled for each touch that had a began without an end or cancel. When the actual touchesEnded gets called, it gets ignored as it no longer matches a touchesBegan in my app.

    It feels a bit like jumping hoops, but this does the trick quit nicely for me.