Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
禁用iPhone 4S/新iPad键盘上的听写按钮_Iphone_Objective C_Ios_Ipad - Fatal编程技术网

禁用iPhone 4S/新iPad键盘上的听写按钮

禁用iPhone 4S/新iPad键盘上的听写按钮,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,我们的是一个医疗保健应用程序。我们在应用程序中有一个符合HIPAA标准的语音识别器,通过它所有的听写都可以进行。医院不希望医生意外地开始与不符合HIPAA的Nuance Dragon服务器通话。所以,我在寻找我可以按下键盘上听写键的方法 我试着在键盘上的听写按钮上放一个假按钮,但在iPad上,分离式底座的概念让麦克风在屏幕上到处移动。这听起来不是一个合理的解决方案。有没有专家可以帮助我 好了,终于找到了!诀窍是观察模式更改通知,然后收集更改模式的标识符(代码似乎避免直接使用私有API,尽管通常似

我们的是一个医疗保健应用程序。我们在应用程序中有一个符合HIPAA标准的语音识别器,通过它所有的听写都可以进行。医院不希望医生意外地开始与不符合HIPAA的Nuance Dragon服务器通话。所以,我在寻找我可以按下键盘上听写键的方法


我试着在键盘上的听写按钮上放一个假按钮,但在iPad上,分离式底座的概念让麦克风在屏幕上到处移动。这听起来不是一个合理的解决方案。有没有专家可以帮助我

好了,终于找到了!诀窍是观察模式更改通知,然后收集更改模式的标识符(代码似乎避免直接使用私有API,尽管通常似乎需要一些私有API的知识),当模式更改为听写时,辞职FirstResponder(这将取消语音听写)。耶!下面是一些代码:

在你的应用程序代理的某个地方(至少我把它放在那里)

然后你就可以

UIView *resignFirstResponder(UIView *theView)
{
    if([theView isFirstResponder])
    {
        [theView resignFirstResponder];
        return theView;
    }
    for(UIView *subview in theView.subviews)
    {
        UIView *result = resignFirstResponder(subview);
        if(result) return result;
    }
    return nil;
}

- (void)inputModeDidChange:(NSNotification *)notification
{        
    // Allows us to block dictation
    UITextInputMode *inputMode = [UITextInputMode currentInputMode];
    NSString *modeIdentifier = [inputMode respondsToSelector:@selector(identifier)] ? (NSString *)[inputMode performSelector:@selector(identifier)] : nil;

    if([modeIdentifier isEqualToString:@"dictation"])
    {
        [UIView setAnimationsEnabled:NO];
        UIView *resigned = resignFirstResponder(window);
        [resigned becomeFirstResponder];
        [UIView setAnimationsEnabled:YES];

        UIAlertView *denyAlert = [[[UIAlertView alloc] initWithTitle:@"Denied" message:nil delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil] autorelease];
        [denyAlert show];
    }
}

好了,终于明白了!诀窍是观察模式更改通知,然后收集更改模式的标识符(代码似乎避免直接使用私有API,尽管通常似乎需要一些私有API的知识),当模式更改为听写时,辞职FirstResponder(这将取消语音听写)。耶!下面是一些代码:

在你的应用程序代理的某个地方(至少我把它放在那里)

然后你就可以

UIView *resignFirstResponder(UIView *theView)
{
    if([theView isFirstResponder])
    {
        [theView resignFirstResponder];
        return theView;
    }
    for(UIView *subview in theView.subviews)
    {
        UIView *result = resignFirstResponder(subview);
        if(result) return result;
    }
    return nil;
}

- (void)inputModeDidChange:(NSNotification *)notification
{        
    // Allows us to block dictation
    UITextInputMode *inputMode = [UITextInputMode currentInputMode];
    NSString *modeIdentifier = [inputMode respondsToSelector:@selector(identifier)] ? (NSString *)[inputMode performSelector:@selector(identifier)] : nil;

    if([modeIdentifier isEqualToString:@"dictation"])
    {
        [UIView setAnimationsEnabled:NO];
        UIView *resigned = resignFirstResponder(window);
        [resigned becomeFirstResponder];
        [UIView setAnimationsEnabled:YES];

        UIAlertView *denyAlert = [[[UIAlertView alloc] initWithTitle:@"Denied" message:nil delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil] autorelease];
        [denyAlert show];
    }
}

您可以创建自己的键盘,并为将接受此口述的文本字段设置inputView。然后,当他们按下任何键时,他们将得到你的键盘,因此你不必覆盖标准键盘上的键,你将能够定制整个东西

self.myButton.inputView = self.customKeyboardView;
下面是一个非常定制的键盘示例

Ray还有一个关于定制键盘的teriffic教程


我希望这会有所帮助。

您可以创建自己的键盘,并为将接受此听写的文本字段设置inputView。然后,当他们按下任何键时,他们将得到你的键盘,因此你不必覆盖标准键盘上的键,你将能够定制整个东西

self.myButton.inputView = self.customKeyboardView;
下面是一个非常定制的键盘示例

Ray还有一个关于定制键盘的teriffic教程


我希望这会有所帮助。

您可以创建UITextField/UITextView的子类,该子类覆盖InsertDictionResult:不插入任何内容


这不会阻止信息被发送,但是您可以显示一个警报,通知他们臀位。

您可以创建一个UITextField/UITextView的子类,该子类覆盖InsertDictionResult:以不插入任何内容


这不会阻止信息的发送,但是您可以显示一个警报,通知他们臀部的位置。

我也有同样的问题,我发现隐藏口述按钮的唯一方法是更改键盘类型。 对我来说,将其更改为电子邮件类型似乎是合理的:

textField.keyboardType = UIKeyboardTypeEmailAddress;

我也有同样的问题,我发现隐藏听写按钮的唯一方法就是改变键盘类型。 对我来说,将其更改为电子邮件类型似乎是合理的:

textField.keyboardType = UIKeyboardTypeEmailAddress;

这是一个基于@BadPirate黑客攻击的Swift 4解决方案。它将触发最初的铃声,说明听写已开始,但听写布局将永远不会出现在键盘上

这不会在键盘上隐藏口述按钮:因此,唯一的选择似乎是使用电子邮件布局


在拥有要禁用听写的
UITextField
的视图控制器的
viewDidLoad
中:

// Track if the keyboard mode changed to discard dictation
NotificationCenter.default.addObserver(self,
                                       selector: #selector(keyboardModeChanged),
                                       name: UITextInputMode.currentInputModeDidChangeNotification,
                                       object: nil)
然后,自定义回调:

@objc func keyboardModeChanged(notification: Notification) {
    // Could use `Selector("identifier")` instead for idSelector but
    // it would trigger a warning advising to use #selector instead
    let idSelector = #selector(getter: UILayoutGuide.identifier)

    // Check if the text input mode is dictation
    guard
        let textField = yourTextField as? UITextField
        let mode = textField.textInputMode,
        mode.responds(to: idSelector),
        let id = mode.perform(idSelector)?.takeUnretainedValue() as? String,
        id.contains("dictation") else {
            return
    }

    // If the keyboard is in dictation mode, hide
    // then show the keyboard without animations
    // to display the initial generic keyboard
    UIView.setAnimationsEnabled(false)
    textField.resignFirstResponder()
    textField.becomeFirstResponder()
    UIView.setAnimationsEnabled(true)

    // Do additional update here to inform your
    // user that dictation is disabled
}

这是一个基于@BadPirate黑客攻击的Swift 4解决方案。它将触发最初的铃声,说明听写已开始,但听写布局将永远不会出现在键盘上

这不会在键盘上隐藏口述按钮:因此,唯一的选择似乎是使用电子邮件布局


在拥有要禁用听写的
UITextField
的视图控制器的
viewDidLoad
中:

// Track if the keyboard mode changed to discard dictation
NotificationCenter.default.addObserver(self,
                                       selector: #selector(keyboardModeChanged),
                                       name: UITextInputMode.currentInputModeDidChangeNotification,
                                       object: nil)
然后,自定义回调:

@objc func keyboardModeChanged(notification: Notification) {
    // Could use `Selector("identifier")` instead for idSelector but
    // it would trigger a warning advising to use #selector instead
    let idSelector = #selector(getter: UILayoutGuide.identifier)

    // Check if the text input mode is dictation
    guard
        let textField = yourTextField as? UITextField
        let mode = textField.textInputMode,
        mode.responds(to: idSelector),
        let id = mode.perform(idSelector)?.takeUnretainedValue() as? String,
        id.contains("dictation") else {
            return
    }

    // If the keyboard is in dictation mode, hide
    // then show the keyboard without animations
    // to display the initial generic keyboard
    UIView.setAnimationsEnabled(false)
    textField.resignFirstResponder()
    textField.becomeFirstResponder()
    UIView.setAnimationsEnabled(true)

    // Do additional update here to inform your
    // user that dictation is disabled
}

有趣的解决方案。您是否知道在听写开始之前调用的任何内容,以便用户在说出任何可能泄露私人信息的内容之前可以得到警告?不幸的是,不知道。您会收到一个录制结束通知(听写录制结束),但无法取消到服务器的传输(据我所知,录音一开始就开始上传)。有趣的解决方案。你知道在听写开始之前会调用什么,这样用户就可以在说出任何可能泄露私人信息的话之前得到提醒吗?不幸的是,不会。你会收到录音结束通知(DictationRecordingDiEnd),但无法取消到服务器的传输(因为我的理解是,一旦开始录制,它就会开始上传)。这是我目前正在考虑的解决方案…似乎是一个可行的解决方案,该死的遗憾是必须自己重新编程键盘。。。(例如,当你把手指放在一个角色上时的小放大镜,等等)知道任何GITHUB/开源项目提供好的替代键盘吗?在我做出回应之前,我尝试了一些谷歌。不幸的是我没有找到任何。如果你真的创造了。你可以考虑把它放在Github上,让其他人一起工作,也许有助于:是的,我也有同样的想法。一旦我们写了我的类,可能就必须让它可用,这样其他人就不会有这个问题。如果它开始得好,我可能会自己动手开发。我想要一个自定义键盘,但完全是基于