问题
Is it possible to detect if the user pressed the power button two times fast? Apple use the way to confirm an Appstore purchase on the new iPhone X with Face-ID. Is there any API available? Want to use it in an similar case for authenticate via Face-ID.
回答1:
No. The system itself controls response to the side (sleep/wake/power) button.
iOS accepts a double-tap on side button to prompt for Face ID authentication only during an Apple-mediated financial transaction — that is, to make a purchase from iTunes / App Store, including in-app purchases, or to complete an online Apple Pay transaction. Outside such circumstances, double-tapping the side button either brings up the UI for an in-person Apple Pay transaction or (if the setting for showing Wallet on double-tap is disabled) does nothing.
Your app is welcome to prompt for Face ID / Touch ID authentication in response to any in-app or on-screen event, but not only is there no API explicitly for responding to the side button or other hardware controls, any attempt to repurpose existing API for such reasons probably wouldn’t get past App Review:
2.5.9 Apps that alter or disable the functions of standard switches, such as the Volume Up/Down and Ring/Silent switches, or other native user interface elements or behaviors will be rejected.
来源:https://stackoverflow.com/questions/47200522/detect-fast-double-power-button-press