I want to enroll Touch ID in the iOS Simulator from the command line so I can run some automated UI feature tests around authorization.
I've tried a few things that didn't work:
xcrun simctl
doesn't have a Touch ID optionosascript
doesn't have accessibility permissions (and I don't like this invasive workaround)If it matters, I'm using Frank and Cucumber for the tests.
To enable this feature, the allowTouchIdEnroll desired capability must be set to true. When allowTouchIdEnroll is set to true the Simulator will be enrolled by default, and the 'Toggle Touch ID Enrollment' changes the enrollment state. Another way to enable touch id is by using mobile: enrollBiometric . More info here.
Just type this command in Terminal: open -a Simulator. app to launch the most recent simulator. Type this command in Terminal to run the Simulator rigth from the its folder.
When in the simulator, hold the option key down and click - this will simulate a two-finger tap!
xcrun simctl spawn 'iPhone X' notifyutil -s com.apple.BiometricKit.enrollmentChanged '1' && xcrun simctl spawn 'iPhone X' notifyutil -p com.apple.BiometricKit.enrollmentChanged
This will enroll fingerprint. Code taken from here
Edit: You can use this for finger touch:
xcrun simctl spawn 'iPhone X' notifyutil -p com.apple.BiometricKit_Sim.fingerTouch.match
xcrun simctl spawn 'iPhone X' notifyutil -p com.apple.BiometricKit_Sim.fingerTouch.nomatch
UPDATE May 2019: Read the accepted answer, that's the way to do it.
Original Answer from 2016: As far as I know there is no way to activate this on the simulator.
Generally, to test something like this, I fake a callback from the Apple component, or pop an alert view if there is no callback expected (like when calling openURL:
, I'll pop an alert view with the URL that should be opened to verify the correct thing would be opened when opening that URL) while testing.
It feels kinda hacky, but it at least tells me that if the Apple component is giving me the expected callback, my application will take the expected action.
How do you tell if it's testing? Well, you've got a couple options.
Jon Reid's got a good post about how to tell if you're testing at runtime here: http://qualitycoding.org/app-delegate-for-tests/ - though he's using it to switch out the app delegate, I've used a similar technique to check whether the app is presently under test or not.
I'm not 100% sure this technique would work with Cucumber and Frank since I don't know if they run in the same process as the tests. For things not running in the same process as the tests (such as XCUI tests) I've passed in ProcessInfo
arguments when the app is being launched so that it knows what to look for. Pain in the ass, and again, hacky, but it does seem to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With