首页 > 解决方案 > Showing the system Emoji keyboard by default on iOS 13

问题描述

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

Prior to returning the UITextInputMode with primaryLanguage that equaled "emoji" would default to showing the Emoji Keyboard (see image below).

Emoji keyboard screen shot

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
    }
}

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

标签: iosswiftkeyboarduikitemoji

解决方案


我为 iOS 13 提交了一份雷达,因为我有一个日文/英文双语应用程序。有些字段是日语,有些是英语,所以显然向用户展示正确的键盘类型而不是让它们来回翻转 20 次是有意义的。

有一个解决方法,那就是在 UIKit 调用“textInputMode”之后,在主线程中你可以这样做:

// has to be done after the textInputMode method is called
if #available(iOS 13, *) {
    textField.keyboardType = textField.keyboardType
} 

这会在使用您想要的 textInputMode 回答后强制键盘重新加载。我通知了他们这个错误,以及获得正确行为的解决方法。

所以在 iOS 13.1 中,这个 bug 没有被修复,但是他们阻止了我的解决方法。

好的。我不会再向他们报告任何错误。相反,如果我找到解决方法,我会使用它。

因此,他们现在似乎正在默默地禁用此功能。它是一个特性,这就是这个方法调用的真正目的,找出应该呈现给用户的输入模式。

如果您有另一种语言并想选择英语,它仍然可以正常工作。

因此,如果我的用户将日语设置为键盘选择,那么我可以强制使用英语键盘。只是不是相反。任何获得日语输入模式的尝试都以英语键盘告终。

编辑:

您可以通过另一种途径解决此问题,但它涉及发现和使用内部 API,这并不简单。您基本上必须找到用于管理点击地球按钮结果的函数。如果您这样做,您实际上是在模拟用户的点击,并且它具有广泛的效果,也就是说,键盘也会为其他应用程序更改。所以不推荐,100%会在App Store提交失败。由于我上次解决方法的结果,我不想发布它。

我认为不可能很容易地理解Apple。我所知道的是:

  1. API 未按已发布的方式运行
  2. 据报道,他们没有修复错误
  3. 自报告之日起,他们(有意或无意)破坏了解决方法

因此,应该囤积未来的解决方法,直到他们的意图明确和/或他们修复了这个错误(这是他们应该做的)。简单地撤销部分 API 而不发布更改是一个主要错误。


推荐阅读