I am trying to listen to plug in/out event for headphones while in background. The problem is that while the events are generated in real-time, I am not able to do handle them in real-time. Whatever code I run in the background gets executed all at once when the user opens the app next time. (some main queue problem?)
I want to send location of the user to a server whenever user plugs out headphone when in background.
What should I do for this? I can't spawn a background thread while in background too (it gets spawned after the user opens the app again). Any ideas?
Thanks in advance!