rjs*_*ing 14 keyboard uikit ios emoji swift
Solution
Here is a full solution/work around for this issue, please up vote Blld's answer as well because this was the vital bit of info needed!
Alternative titles to aid search
UITextInputMode.primaryLanguage to emojiPrior to ios13 returning the UITextInputMode with primaryLanguage that equaled "emoji" would default to showing the Emoji Keyboard (see image below).
Example code for returning the "emoji" UITextInputMode.
//
// ViewController.swift
// Keyboard Info
//
// Created by Richard Stelling on 30/09/2019.
// Copyright © 2019 Richard Stelling. All rights reserved.
//
import UIKit
class TestButton: UIButton, UIKeyInput {
var hasText: Bool = true
func insertText(_ text: String) { print("\(text)") }
func deleteBackward() {}
override var canBecomeFirstResponder: Bool { return true }
override var canResignFirstResponder: Bool { return true }
override var textInputMode: UITextInputMode? {
for mode in UITextInputMode.activeInputModes {
if mode.primaryLanguage == "emoji" {
return mode
}
}
return nil
}
}
Run Code Online (Sandbox Code Playgroud)
Running this code on iOS 12 will set the keyboard to the system Emoji Keyboard, but on iOS 13 it has no affect.
Is this a known bug? Is there a workaround?
Updates
您需要textinputcontextidentifier在 textField 上进行设置,以便 iOS 知道在哪里保存自定义textInputMode
它没有写在文档中,但它有效。
参考:https : //developer.apple.com/documentation/uikit/uiresponder/1621091-textinputcontextidentifier
注意:确保您启用了表情符号键盘。
这似乎是一个 iOS 13 错误,解决方法(对于设备,这不会影响模拟器)是覆盖该textInputContextIdentifier属性并返回一个非 nil 值。
//
// ViewController.swift
// Keyboard Info
//
// Created by Richard Stelling on 30/09/2019.
// Copyright © 2019 Richard Stelling. All rights reserved.
//
import UIKit
class TestButton: UIButton, UIKeyInput {
var hasText: Bool = true
override var textInputContextIdentifier: String? { "" } // return non-nil to show the Emoji keyboard ¯\_(?)_/¯
func insertText(_ text: String) { print("\(text)") }
func deleteBackward() {}
override var canBecomeFirstResponder: Bool { return true }
override var canResignFirstResponder: Bool { return true }
override var textInputMode: UITextInputMode? {
for mode in UITextInputMode.activeInputModes {
if mode.primaryLanguage == "emoji" {
return mode
}
}
return nil
}
}
Run Code Online (Sandbox Code Playgroud)
感谢blld的回答。
我为此针对iOS 13提出了要求,因为我有双语的日语/英语应用程序。有些字段是日语,有些是英语,因此显然向用户展示正确的键盘类型是有意义的,而不是使它们来回翻转20次。
有一个解决方法,就是在UIKit调用“ textInputMode”之后,可以在主线程中执行以下操作:
// has to be done after the textInputMode method is called
if #available(iOS 13, *) {
textField.keyboardType = textField.keyboardType
}
Run Code Online (Sandbox Code Playgroud)
这将在回答所需的textInputMode后强制重新加载键盘。我向他们通报了该错误以及解决方法,以获取正确的行为。
因此,在iOS 13.1中,该错误未得到修复,但是它们阻止了我的解决方法。
真好 我不会再向他们报告任何错误。相反,如果我找到解决方法,我只会使用它。
因此,似乎他们现在正在静默禁用此功能。这是一个功能,从字面上讲,这就是此方法调用的目的,以找出应向用户提供哪种输入模式。
即使您使用另一种语言并想要选择英语,它仍然可以正常工作。
因此,如果我的用户将日语设置为键盘选择,则可以强制使用英语键盘。并非相反。任何试图获得日语输入模式的尝试都将以英语键盘结束。
编辑:
您可以使用另一种方法来解决此问题,但是它涉及发现和使用内部API,这并不容易。您实际上必须找到用于管理单击地球按钮的结果的功能。如果这样做,则实际上是在模拟用户的点击,并且具有广泛的效果,也就是说,其他应用程序的键盘也将更改。因此,不建议这样做,因为100%的应用商店提交都会失败。由于最后一个解决方法的结果,我不想发布它。
我认为不可能很容易理解苹果。我所知道的是:
因此,应该future积未来的解决方法,直到其意图明确和/或他们修复了此错误(这是他们应该做的)。仅仅撤销部分API而不发布更改是一个主要的错误。
| 归档时间: |
|
| 查看次数: |
763 次 |
| 最近记录: |