Instantly share code, notes, and snippets.

Embed
What would you like to do?
UIDebuggingInformationOverlay for iOS 10, 11, and 12
#import <objc/runtime.h>
@interface DebuggingOverlay: NSObject
@end
@implementation DebuggingOverlay
+ (void)toggleOverlay {
id debugInfoClass = NSClassFromString(@"UIDebuggingInformationOverlay");
// In iOS 11, Apple added additional checks to disable this overlay unless the
// device is an internal device. To get around this, we swizzle out the
// -[UIDebuggingInformationOverlay init] method (which returns nil now if
// the device is non-internal), and we call:
// [[UIDebuggingInformationOverlayInvokeGestureHandler mainHandler] _handleActivationGesture:(UIGestureRecognizer *)]
// to show the window, since that now adds the debugging view controllers, and calls
// [overlay toggleVisibility] for us.
if (@available(iOS 11.0, *)) {
id handlerClass = NSClassFromString(@"UIDebuggingInformationOverlayInvokeGestureHandler");
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Swizzle init of debugInfo class to just call [UIWindow init]
Method initMethod = class_getInstanceMethod(debugInfoClass, @selector(init));
IMP newInit = method_getImplementation(class_getInstanceMethod([UIWindow class], @selector(init)));
method_setImplementation(initMethod, newInit);
});
id debugOverlayInstance = [debugInfoClass performSelector:NSSelectorFromString(@"overlay")];
[debugOverlayInstance setFrame:[[UIScreen mainScreen] bounds]];
UIGestureRecognizer *dummyGestureRecognizer = [[UIGestureRecognizer alloc] init];
dummyGestureRecognizer.state = UIGestureRecognizerStateEnded;
id handler = [handlerClass performSelector:NSSelectorFromString(@"mainHandler")];
[handler performSelector:NSSelectorFromString(@"_handleActivationGesture:") withObject:dummyGestureRecognizer];
} else {
id debugOverlayInstance = [debugInfoClass performSelector:NSSelectorFromString(@"overlay")];
[debugOverlayInstance performSelector:NSSelectorFromString(@"toggleVisibility")];
}
}
@end
@mohammedshahid

This comment has been minimized.

Copy link

mohammedshahid commented Dec 5, 2017

Hi Ian,

How to call this toggleOverlay method from swift class .

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