Catching hardware buttons on iOS when my app is in

2019-08-31 06:19发布

问题:

I would like to execute some code when user presses one of home, power or volume buttons(it doesn't matter, which of these).

I would like to catch events even application is minimized to background and device is sleeping.

So primary task is processing events, when device is inside user's pocket and the user presses button, but not takes out the device.

Is that possible? If it isnt't possible for power button, may be it's possible for volume or home buttons? How can I do it?

回答1:

Your application cannot interact with the hardware buttons on an iOS device. Your application can receive notification that it has entered the background (which may be a side-effect of the use pressing the home button, for example) but that is about all



回答2:

There is idea about volume buttons, if you create player instance you can get notifications about volume change, not sure that is still work but you can try.

see answers here: program access to iPhone volume buttons