Last active
December 3, 2025 12:20
-
-
Save Amzd/c3171021488fc82d1b68cfd8e89ada7b to your computer and use it in GitHub Desktop.
Detect taps in status bar on iOS 13+. Confirmed to work on iOS 26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| /// https://gist.github.com/Amzd/c3171021488fc82d1b68cfd8e89ada7b | |
| extension UIStatusBarManager { | |
| public static var statusBarTappedNotification: Notification.Name = { | |
| if let originalMethod = class_getInstanceMethod(UIStatusBarManager.self, Selector(("handleTapAction:"))), | |
| let swizzledMethod = class_getInstanceMethod(UIStatusBarManager.self, #selector(_handleTapAction)), | |
| // Prevent crash in case an argument is added/removed in the future | |
| method_getNumberOfArguments(originalMethod) == method_getNumberOfArguments(swizzledMethod) { | |
| method_exchangeImplementations(originalMethod, swizzledMethod) | |
| } | |
| return .init("statusBarSelected") | |
| }() | |
| @objc private func _handleTapAction(_ sender: Any?) { | |
| _handleTapAction(sender) // Call the original implementation | |
| NotificationCenter.default.post(name: UIStatusBarManager.statusBarTappedNotification, object: nil) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NotificationCenter.default.addObserver(self, selector: #selector(statusBarTapped), name: UIStatusBarManager.statusBarTappedNotification, object: nil) | |
| @objc func statusBarTapped(notification: Notification) { | |
| // React to status bar tap | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/a/79836058/3393964