keyboardWillShowNotification is sent multiple times in iOS simulator
Originator: | daniel | ||
Number: | rdar://FB12597594 | Date Originated: | 2023-07-13 |
Status: | Open | Resolved: | |
Product: | Simulator | Product Version: | Xcode 15 beta 4 |
Classification: | Reproducible: | always |
In an iOS 17 simulator running a UIKit app, when a text field gains first reponder status, the UIResponder.keyboardFrameEndUserInfoKey notification is received multiple times. The first time the field becomes the first responder, the notification is received twice. When the field resigns first responder and then becomes first responder again, the notification is even received three times. I can reproduce this reliably in the iOS 17 iPhone 14 Pro simulator as installed with Xcode 15.0 beta 4 (15A5195m). This is independent of whether I build the app with Xcode 15 beta or with Xcode 14.3.1, as long as I run it in the iOS 17 simulator. I can't reproduce it on an iPhone 12 Pro running iOS 16.5.1 (c), but I do see a similar bug on a iOS 16.4 simulator: There, only one keyboardWillShowNotification notification is sent when the text field becomes the first responder, but when it resigns first responder, it receives a keyboardWillShowNotification and a keyboardWillHideNotification in short succession. I unfortunately can't test on iOS 17 on a real device because I don't have a spare one that I can upgrade to the beta at the moment. I attached a full demo project. Here's the most relevant code (from viewDidLoad of a view controller with a text field): NotificationCenter.default .publisher(for: UIResponder.keyboardWillShowNotification) .sink { notification in print("Show: \(notification.userInfo![UIResponder.keyboardFrameEndUserInfoKey]!)") } .store(in: &tokens) NotificationCenter.default .publisher(for: UIResponder.keyboardWillHideNotification) .sink { notification in print("Hide: \(notification.userInfo![UIResponder.keyboardFrameEndUserInfoKey]!)") } .store(in: &tokens) Console output when opening and dismissing the keyboard on iOS 17 simulator the first time after app launch: Show: NSRect: {{0, 516}, {393, 336}} Show: NSRect: {{0, 516}, {393, 336}} Hide: NSRect: {{0, 852}, {393, 336}} … and the second time after app launch: Show: NSRect: {{0, 852}, {393, 0}} Show: NSRect: {{0, 516}, {393, 336}} Show: NSRect: {{0, 516}, {393, 336}} Hide: NSRect: {{0, 852}, {393, 336}}
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Partly fixed in Xcode 15 beta 8. The iOS 17 simulator now shows the same behavior as the iOS 16 simulator, in that only one keyboardWillShowNotification notification is sent when the text field becomes the first responder, but when it resigns first responder, it receives a keyboardWillShowNotification and a keyboardWillHideNotification in short succession.