5

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?

James Webster
  • 31,873
  • 11
  • 70
  • 114
Randomblue
  • 112,777
  • 145
  • 353
  • 547
  • I suspect that Apple really takes over the app when the Touch ID screen is shown. I know that my app doesn't get rotation methods and I also know that when you examine your app with a visual inspector like Reveal.app the Touch ID screen isn't even part of the view hierarchy. Hope this helps... – Paul Cezanne Apr 18 '15 at 13:52
  • 1
    Wow, I didn't realise things like Reveal App existed. Seems useful. – Randomblue Apr 18 '15 at 13:56
  • It is an amazing product. Much of what it does can be done in Xcode now, but not on a device, and if you are capturing video or using Touch ID you need a real device. – Paul Cezanne Apr 18 '15 at 17:42

2 Answers2

4

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.

Paul Cezanne
  • 8,629
  • 7
  • 59
  • 90
  • What exactly do you mean by "lose control"? Because the app goes in the state `applicationWillResignActive` with Touch ID, and usually in that state the camera continues running (e.g. if the user double taps the home button). – Randomblue Apr 26 '15 at 18:22
  • Ok, I've tried running the camera in a background mode (both with `dispatch_async` and `addOperationWithBlock`). Still freezes. – Randomblue Apr 26 '15 at 18:27
  • 1
    applicationDidResignActive is what I meant. Does it get there? It sounds like it does, and that the camera does run in that state, unless Touch ID is up. That stinks for you. – Paul Cezanne Apr 26 '15 at 20:38
  • Yeah, that's exactly what I'm seeing. – Randomblue Apr 27 '15 at 06:32
  • I guess I'd submit a Radar bug then and then make some UX decisions. How about you overlay a black, slightly transparent, UIView over the camera so the black screen isn't as obvious? – Paul Cezanne Apr 27 '15 at 09:50
1

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

Dan Loughney
  • 4,647
  • 3
  • 25
  • 40