我怎么知道键盘是否在短信应用程序中打开?

问题描述 投票:0回答:1

我想检测主要用于消息应用程序的iPhone中第三方应用程序的键盘事件。我想知道用户是否在消息传递应用程序中键入消息(文本消息)。>>

请让我知道是否有人对此有想法。

谢谢

我想检测主要用于消息应用程序的iPhone中第三方应用程序的键盘事件。我想知道用户是否在消息传递应用程序中键入消息(文本消息)。请让我知道是否有人有...

ios swift iphone keyboard message
1个回答
0
投票
extension UIApplication {
    // Checks if the view hierarchy of application contains `UIRemoteKeyboardWindow` if it does then keyboard is presented
    var hasKeyboardPresented: Bool {
        if let keyboardWindowClass = NSClassFromString("UIRemoteKeyboardWindow"),
            self.windows.contains(where: { $0.isKind(of: keyboardWindowClass) }) {
            return true
        } else {
            return false
        }
    }
}

//Then check if keyboard is present,

if UIApplication.shared.hasKeyboardPresented {
     print("Keyboard presented")
} else { 
     print("Keyboard is not presented")
}
© www.soinside.com 2019 - 2024. All rights reserved.