Skip to content

Instantly share code, notes, and snippets.

@zats
Last active Dec 17, 2019
Embed
What would you like to do?

Debug Overrides

This is a copy of debug overrides available through Xcode UI that boils down to calling certain private APIs. It only overrides the values within your app while it's running, restarting the app will reset back to the system values

This simply wraps overrides found in /Applications/Xcode.app/Contents/PlugIns/IDEiOSDebugger.ideplugin/Contents/Resources/IDEiOSDebugger.xcplugindata into C functions Probably not a good idea to ship those to the AppStore Most of APIs work by setting one @YES or @NO to set value explicitly, or by setting nil to reset to the system value

#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, DBGInterfaceStyleOverride) {
DBGInterfaceStyleOverrideNone = 0,
DBGInterfaceStyleOverrideLight,
DBGInterfaceStyleOverrideDark,
};
#ifdef __cplusplus
extern "C" {
#endif
/**
* No Override = nil
* Enabled = @YES
* Disabled = @NO
*/
void DBGSetSmartInvert(NSNumber *value);
/**
* No Override = nil
* Enabled = @YES
* Disabled = @NO
*/
void DBGSetGrayscale(NSNumber *value);
/**
* No Override = nil
* Enabled = @YES
* Disabled = @NO
*/
void DBGSetButtonShapes(NSNumber *value);
/**
* No Override = nil
* Enabled = @YES
* Disabled = @NO
*/
void DBGSetOnOffLabels(NSNumber *value);
/**
* No Override = nil
* Reduced = @YES
* Default = @NO
*/
void DBGSetReduceTransparency(NSNumber *value);
/**
* No Override = 0
* Light = 1
* Dark = 2
*/
void DBGSetInterfaceStyle(DBGInterfaceStyleOverride value);
/**
* No Override = nil
* Enabled = @YES
* Disabled = @NO
*/
void DBGSetDifferentiateWithoutColor(NSNumber *value);
/**
* No Override = nil
* Reduced = @YES
* Default = @NO
*/
void DBGSetReduceMotion(NSNumber *value);
/**
* No Override = nil
* Extra Small = UIContentSizeCategoryExtraSmall
* Small = UIContentSizeCategorySmall
* Medium = UIContentSizeCategoryMedium
* Large = UIContentSizeCategoryLarge
* XL = UIContentSizeCategoryExtraLarge
* XXL = UIContentSizeCategoryExtraExtraLarge
* XXXL = UIContentSizeCategoryExtraExtraExtraLarge
* Accessibility Medium = UIContentSizeCategoryAccessibilityMedium
* Accessibility Large = UIContentSizeCategoryAccessibilityLarge
* Accessibility XL = UIContentSizeCategoryAccessibilityExtraLarge
* Accessibility XXL = UIContentSizeCategoryAccessibilityExtraExtraLarge
* Accessibility XXXL = UIContentSizeCategoryAccessibilityExtraExtraExtraLarge
*/
void DBGSetDynamicType(UIContentSizeCategory value);
/**
* No Override = nil
* Increased = @YES
* Default = @NO
*/
void DBGSetIncreaseContrast(NSNumber *value);
/**
* No Override = nil
* Enabled = @YES
* Disabled = @NO
*/
void DBGSetBoldText(NSNumber *value);
#ifdef __cplusplus
}
#endif
#import "DebugOverrides.h"
#import <objc/runtime.h>
@interface DebugOverridesSelectorsHost: NSObject
+ (instancetype)shared;
- (instancetype)initWithContentSizeCategory:(UIContentSizeCategory)value;
- (void)setSmartInvert:(NSNumber *)value;
- (void)setGrayscale:(NSNumber *)value;
- (void)setButtonShapes:(NSNumber *)value;
- (void)setOnOffLabels:(NSNumber *)value;
- (void)setReduceTransparency:(NSNumber *)value;
- (void)_setDebugUserInterfaceStyleOverride:(DBGInterfaceStyleOverride)value;
- (void)setDifferentiateWithoutColor:(NSNumber *)value;
- (void)setReduceMotion:(NSNumber *)value;
- (void)overrideSystemWithPreference:(id)value;
- (void)setIncreaseContrast:(NSNumber *)value;
- (void)setBoldText:(NSNumber *)value;
@end
void DBGSetSmartInvert(NSNumber *value) {
[[objc_getClass("AccessibilitySupportOverrides") shared] setSmartInvert:value];
}
void DBGSetGrayscale(NSNumber *value) {
[[objc_getClass("AccessibilitySupportOverrides") shared] setGrayscale:value];
}
void DBGSetButtonShapes(NSNumber *value) {
[[objc_getClass("AccessibilitySupportOverrides") shared] setButtonShapes:value];
}
void DBGSetOnOffLabels(NSNumber *value) {
[[objc_getClass("AccessibilitySupportOverrides") shared] setOnOffLabels:value];
}
void DBGSetReduceTransparency(NSNumber *value) {
[[objc_getClass("AccessibilitySupportOverrides") shared] setReduceTransparency:value];
}
void DBGSetInterfaceStyle(DBGInterfaceStyleOverride value) {
[objc_getClass("UIApplication") _setDebugUserInterfaceStyleOverride:value];
}
void DBGSetDifferentiateWithoutColor(NSNumber *value) {
[[objc_getClass("AccessibilitySupportOverrides") shared] setDifferentiateWithoutColor:value];
}
void DBGSetReduceMotion(NSNumber *value) {
[[objc_getClass("AccessibilitySupportOverrides") shared] setReduceMotion:value];
}
void DBGSetDynamicType(UIContentSizeCategory value) {
[objc_getClass("UIContentSizeCategoryPreference") overrideSystemWithPreference:[[objc_getClass("UIContentSizeCategoryPreference") alloc] initWithContentSizeCategory:value]];
}
void DBGSetIncreaseContrast(NSNumber *value) {
[[objc_getClass("AccessibilitySupportOverrides") shared] setIncreaseContrast:value];
}
void DBGSetBoldText(NSNumber *value) {
[[objc_getClass("AccessibilitySupportOverrides") shared] setBoldText:value];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment