在 iOS 13 上默认显示系统表情符号键盘

Showing the system Emoji keyboard by default on iOS 13(在 iOS 13 上默认显示系统表情符号键盘)

本文介绍了在 iOS 13 上默认显示系统表情符号键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

这是针对此问题的

返回表情符号"的示例代码UITextInputMode.

////ViewController.swift//键盘信息////由 Richard Stelling 于 2019 年 9 月 30 日创建.//版权所有 © 2019 Richard Stelling.版权所有.//导入 UIKit类TestButton:UIButton,UIKeyInput {var hasText: Bool = truefunc insertText(_ text: String) { print("(text)") }函数 deleteBackward() {}覆盖 var canBecomeFirstResponder: Bool { return true }覆盖 var canResignFirstResponder: Bool { return true }覆盖 var textInputMode: UITextInputMode?{对于 UITextInputMode.activeInputModes 中的模式 {如果 mode.primaryLanguage == "emoji" {返回模式}}返回零}}

在 iOS 12 上运行此代码会将键盘设置为系统表情符号键盘,但在 iOS 13 上没有任何影响.

这是一个已知的错误吗?有解决方法吗?

更新

  • 应 @Navillus 要求,活动输入模式"的完整列表是;"zh-CN", "emoji"
  • 经过测试和确认;13.0、13.1、13.1.1、13.1.2 和 13.2(种子 1)

解决方案

注意:确保您已启用表情符号键盘.

这似乎是 iOS 13 的错误,解决方法(对于设备,这不会影响模拟器)是覆盖 textInputContextIdentifier 属性并返回非零值.

////ViewController.swift//键盘信息////由 Richard Stelling 于 2019 年 9 月 30 日创建.//版权所有 © 2019 Richard Stelling.版权所有.//导入 UIKit类TestButton:UIButton,UIKeyInput {var hasText: Bool = true覆盖 var textInputContextIdentifier: String?{ "" }//返回非 nil 以显示 Emoji 键盘¯\_(ツ)_/¯func insertText(_ text: String) { print("(text)") }函数 deleteBackward() {}覆盖 var canBecomeFirstResponder: Bool { return true }覆盖 var canResignFirstResponder: Bool { return true }覆盖 var textInputMode: UITextInputMode?{对于 UITextInputMode.activeInputModes 中的模式 {如果 mode.primaryLanguage == "emoji" {返回模式}}返回零}}

<块引用>

感谢 blld 的回答.

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

  • Showing the Emoji keyboard as default for a UIKeyInput object (in iOS 13)
  • Force iOS 13 to show the Emoji keyboard
  • Setting the UITextInputMode.primaryLanguage to emoji
  • Programatically set the keyboard to emoji

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

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

  • Requested by @Navillus, the full list of "active input modes" is; "en-GB", "emoji"
  • Tested and confirmed on; 13.0, 13.1, 13.1.1, 13.1.2 and 13.2 (seed 1)

解决方案

NB: Make sure you have the Emoji keyboard enabled.

This seems to be an iOS 13 bug, the work around (for devices, this does not affect the Simulator) is to override the textInputContextIdentifier property and return a non-nil value.

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

Thanks to blld for his answer.

这篇关于在 iOS 13 上默认显示系统表情符号键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 iOS 13 上默认显示系统表情符号键盘

基础教程推荐