我想检测主要用于消息应用程序的iPhone中第三方应用程序的键盘事件。我想知道用户是否在消息传递应用程序中键入消息(文本消息)。>>
请让我知道是否有人对此有想法。
谢谢
我想检测主要用于消息应用程序的iPhone中第三方应用程序的键盘事件。我想知道用户是否在消息传递应用程序中键入消息(文本消息)。请让我知道是否有人有...
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")
}