Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As far as I can tell, there's no public API for detecting when dictation has started.</p> <p>If you <strong>really</strong> want to do it, and you want to be in the App Store, you can probably get away with the following approach, but <strong>it is totally unsupported</strong>, <strong>it might get you rejected anyway</strong>, and <strong>it is likely to break in a future version of iOS</strong>.</p> <p>The text system posts some undocumented notifications <em>after</em> changing to or from the dictation “keyboard”. Two of them are posted both on a change to it <em>and</em> a change from it, with these names:</p> <ul> <li><code>UIKeyboardCandidateCorrectionDidChangeNotification</code></li> <li><code>UIKeyboardLayoutDidChangedNotification</code></li> </ul> <p>Note that the second one has a strange verb conjugation. That is not a typo. (Well, it's not <em>my</em> typo.)</p> <p>These notices are also posted at other times, so you can't just observe them and assume the dictation state has changed. You'll need to do more checking when you receive the notification. So, add yourself as an observer of one of those notifications. The first one seems less likely to go away or be renamed in the future.</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkForDictationKeyboard:) name:@"UIKeyboardCandidateCorrectionDidChangeNotification" object:nil]; ... </code></pre> <p>When you receive the notification, you'll want to see whether the dictation view is showing:</p> <pre><code>- (void)checkForDictationKeyboard:(NSNotification *)note { if ([self isShowingDictationView]) { NSLog(@"showing dictation view"); } else { NSLog(@"not showing dictation view"); } } </code></pre> <p>To see whether it's showing, check each window except your own application window. Normally, the only other window is the text system's window.</p> <pre><code>- (BOOL)isShowingDictationView { for (UIWindow *window in [UIApplication sharedApplication].windows) { if (window == self.window) continue; if (containsDictationView(window)) return YES; } return NO; } </code></pre> <p>Recursively walk the view hierarchy checking for a view whose class name contains the string “DictationView”. The actual class name is <code>UIDictationView</code> but by not using the whole name you're less likely to be rejected from the App Store.</p> <pre><code>static BOOL containsDictationView(UIView *view) { if (strstr(class_getName(view.class), "DictationView") != NULL) return YES; for (UIView *subview in view.subviews) { if (containsDictationView(subview)) return YES; } return NO; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload