**無法在非越獄設備上實現**。iOS 系統設計:
WKWebView,監聽 UIKeyboardWillShowNotification,檢測到藍牙鍵盤連接(GCKeyboard 框架)時調用 [webView endEditing:YES] 收起鍵盤。iOS 13+ 可用 GCKeyboard 監聽硬件鍵盤連接狀態:
[[NSNotificationCenter defaultCenter] addObserverForName:GCKeyboardDidConnectNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
GCKeyboard *keyboard = note.object;
if (keyboard) {
[self.webView endEditing:YES]; // 收起虛擬鍵盤
}
}];
但此代碼**僅在自家 WKWebView 有效**,無法作用於 Safari 瀏覽器。