我们的医疗保健应用程序。我们在应用程序中有一个符合HIPAA标准的语音识别器,通过它可以进行所有的听写。医院不希望医生不小心开始与不符合HIPAA标准的Nuance Dragon服务器对话。所以,我正在寻找可以在键盘上按下听写键的方法。
我尝试在键盘上的Dictation按钮上放置一个假按钮,但在iPad上,分离式底座概念使麦克风在整个屏幕上移动。这听起来不是一个合理的解决方案。那里有专家可以帮助我吗?
答案 0 :(得分:14)
你的应用代表中的某个地方(至少我把它放在那里)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(inputModeDidChange:) name:@"UITextInputCurrentInputModeDidChangeNotification"
object:nil];
然后你可以
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];
}
}
答案 1 :(得分:10)
您可以创建自己的键盘并为接受此听写的文本字段设置inputView。然后当他们按任意键时他们会得到你的键盘,因此你不必覆盖标准键盘上的键,你就可以自定义整个键盘。
self.myButton.inputView = self.customKeyboardView;
这是一个极其自定义键盘的示例
http://blog.carbonfive.com/2012/03/12/customizing-the-ios-keyboard/
Ray还有一个关于自定义键盘的teriffic教程。
http://www.raywenderlich.com/1063/ipad-for-iphone-developers-101-custom-input-view-tutorial
我希望有所帮助。
答案 2 :(得分:7)
我有同样的问题,我发现隐藏听写按钮的唯一方法是改变键盘类型。 对我来说,将其更改为电子邮件类型似乎是合理的:
textField.keyboardType = UIKeyboardTypeEmailAddress;
答案 3 :(得分:1)
您可以创建UITextField / UITextView的子类来覆盖insertDictationResult:不插入任何内容。
这不会阻止发送信息,但您可以显示警告,通知他们臀位。
答案 4 :(得分:0)
这是基于@BadPirate的hack的Swift 4解决方案。它会触发初始铃声,说明听写已开始,但听写布局将永远不会出现在键盘上。
这不会从键盘上隐藏听写按钮:为此,唯一的选择似乎是使用带有UIKeyboardType.emailAddress的电子邮件布局。
在拥有要禁用听写功能的viewDidLoad
的视图控制器的UITextField
中:
// 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
}