Randomblue
Randomblue

Reputation: 116273

Touch ID freezes AVCaptureDevice

I have an AVCaptureDevice to display a live camera preview on screen.

When a Touch ID view is overlaid on the camera preview (using CAContext's evaluatePolicy), the camera preview freezes. When the Touch ID view is dismissed, the camera preview flashes a black screen before restarting.

Both the freezing and the black screen flash are problematic. How can I keep the camera preview alive with the Touch ID view overlaid?

Upvotes: 5

Views: 390

Answers (2)

Dan Loughney
Dan Loughney

Reputation: 4677

I agree with Paul Cezanne, I don't think you can do the capture while the TouchID process is active. While I don't see any specific information in either the docs or the header files, through some testing you can see what is happening.

First, the TouchID prompt is running outside of your process.
1. Run your TouchID enabled app on a device in the debugger.
2. Get the app to display the TouchID prompt.
3. In Xcode, pause the app.

Normally, the app would be frozen on the device, but in this case, you can still use your fingerprint or the cancel button to close the dialog. Once you close the TouchID prompt, the app is paused as you would expect.

Set a breakpoint in the evaluatePolicy callback. Accept TouchID with your finger print and you'll see that block is getting called from CoreAuthentication.daemon.

-[ViewController startTouchID:]_block_invoke at .../testTouchIDThreadding/testTouchIDThreadding/ViewController.m:60
-[LAContext evaluatePolicy:options:reply:]_block_invoke () /*THIS IS MY BLOCK*/
...
-[NSXPCConnection _sendInvocation:withProxy:remoteInterface:withErrorHandler:timeout:userInfo:]_block_invoke310 ()
...
Enqueued from com.apple.NSXPCConnection.m-user.com.apple.CoreAuthentication.daemon (Thread 3)Queue : com.apple.NSXPCConnection.m-user.com.apple.CoreAuthentication.daemon (serial)
...

Since TouchID is leveraging the device hardware to read the thumbprint and compare it to the print stored on chip I think that needs to restrict access to any other device hardware while the process is executing.

From your experience and a test app I just threw together, this seems to be true. I opened the camera using UIImagePickerController and while open, I called laContext evaluatePolicy:... and it paused the camera capture.

So in summary when you are using the TouchID validation:
- Your process is still the active app, but you have called out of your process
- Apple is restricting access to the device hardware for the duration

Upvotes: 1

Paul Cezanne
Paul Cezanne

Reputation: 8741

I'm not sure that this is possible. The app seems to lose control when the Touch ID alert is on the screen. I know that our app doesn't get rotation events when the dialog is up, and I know when I examine the view hierarchy with Reveal.app I don't see the Touch ID view in my hierarchy.

Can you run the camera in a background mode? That might do the trick, but I don't think camera use is permitted in the background.

Upvotes: 4

Related Questions