I found out that this problem disappears after rebooting macOS or after logging out and logging in again. I tried to do something else that could stop this problem, such as closing all applications on a macbook, switching desktops, putting the OS into standby mode and then returning, but the only thing that makes the problem go away is to log out or restart the computer OS
So, when the problem disappeared, I launch my application and just touch the trackpad that sends touchsBeganWithEvent. Then after a few hours, the problem reappears, and touchBeganWithEvent no longer works until I make a gesture like squeezing or scrolling. If I close my application and start again, I need to make a gesture again.
Does anyone know why this is happening?