Skip to content

Instantly share code, notes, and snippets.

@Amzd
Last active December 3, 2025 12:20
Show Gist options
  • Select an option

  • Save Amzd/c3171021488fc82d1b68cfd8e89ada7b to your computer and use it in GitHub Desktop.

Select an option

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
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)
}
}
NotificationCenter.default.addObserver(self, selector: #selector(statusBarTapped), name: UIStatusBarManager.statusBarTappedNotification, object: nil)
@objc func statusBarTapped(notification: Notification) {
// React to status bar tap
}
@Amzd
Copy link
Author

Amzd commented Dec 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment