title: iPad: Detecting External Keyboard
body: <p>My app uses a <code>UIAccessoryView</code> to provide additional keyboard functionality (such as forward/backward tabs and arrows keys) for the virtual keyboard, but that causes UIKeyboardDidShowNotification to fire even when a physical keyboard is present (the accessory appears at the bottom of the screen).</p>
  
  <p>I'd like to check if a physical keyboard is attached when handling UIKeyboardWillShowNotification, to prevent the accessory view from appearing and to prevent my custom view from scrolling up (to make room for the non-existent virtual keyboard).</p>
  
  <p>I've tried examining the <code>UIKeyboardFrameEndUserInfoKey</code> key, but it returns a real size for the virtual keyboard, in spite of nothing being displayed.</p>
  
  <p>Is there any way to detect the presence of a physical keyboard to prevent this unwanted behaviour?</p>
  
  <hr>
  
  <p>Hmm, the plot thickens.</p>
  
  <p>I tried disabling the input accessory by returning nil from the inputAccessoryView property of the Responder object which triggers the keyboard.  That suppresses <code>UIKeyboardWillShowNotification</code> and <code>UIKeyboardDidShowNotification</code> when there is a physical keyboard present, but keeps these notifications when there is no such keyboard.  All good so far.</p>
  
  <p>Then I tried re-enabling inputAccessoryView only after <code>UIKeyboardWillShowNotification</code> had been received. This only fires when a virtual keyboard is needed, so it should allow me to reintroduce the accessory view in those circumstances. Or so I thought.</p>
  
  <p>Unfortunately, it seems the OS doesn't check inputAccessoryView <em>after</em> <code>UIKeyboardWillShowNotification</code>, so it fails to show the accessory view when it is needed :o(</p>
  
  <p>That leaves me with two options:</p>
  
  <ul>
  <li>Include the input accessory view, giving extra functionality for virtual keyboard users, but lose the ability to detect a physical keyboard and hence not supporting physical devices; or</li>
  <li>Exclude the input accessory altogether, preventing most users from accessing the extra keys, but allowing the app to work with a physical keyboard.</li>
  </ul>
  
  <p>Not a great choice, so I'm still keen to see if anyone else has addressed this problem!</p>