Compare commits

..

10 Commits

Author SHA1 Message Date
Ryan Olson ebf5254629 Guard usage of class only available in simulator builds 2015-09-21 14:03:16 -06:00
Ryan Olson e199b529c8 Add simulator shortcut info to README 2015-09-21 13:54:08 -06:00
Ryan Olson 06edea64ae Add help menu listing keyboard shortcuts 2015-09-21 13:54:08 -06:00
Ryan Olson 6d3afe36d1 Expand default FLEX keyboard shortcuts 2015-09-21 13:54:08 -06:00
Ryan Olson b22d2b57a2 Add support for keyboard shortcuts in the simulator 2015-09-21 13:54:08 -06:00
Ryan Olson b453086936 Pragma gardening 2015-09-19 21:56:51 -06:00
Ryan Olson 103489c566 Fix header documentatin 2015-09-19 21:56:24 -06:00
Ryan Olson 3dd27557ea Move swizzling helpers into FLEXUtility 2015-09-19 14:10:41 -06:00
Ryan Olson a64188dd5e Simplify network debugging settings
Having two switches to enable network debugging was confusing. One switch now enables network debugging and persists across launches of the app.
2015-09-19 13:56:46 -06:00
Ryan Olson 44e428655a Replace deprecated percent encoding string transformation method 2015-09-19 13:30:30 -06:00
16 changed files with 814 additions and 164 deletions
@@ -17,6 +17,17 @@
- (BOOL)shouldReceiveTouchAtWindowPoint:(CGPoint)pointInWindowCoordinates;
- (BOOL)wantsWindowToBecomeKey;
// Keyboard shortcut helpers
- (void)toggleSelectTool;
- (void)toggleMoveTool;
- (void)toggleViewsTool;
- (void)toggleMenuTool;
- (void)handleDownArrowKeyPressed;
- (void)handleUpArrowKeyPressed;
- (void)handleRightArrowKeyPressed;
- (void)handleLeftArrowKeyPressed;
@end
@protocol FLEXExplorerViewControllerDelegate <NSObject>
@@ -14,6 +14,7 @@
#import "FLEXGlobalsTableViewController.h"
#import "FLEXObjectExplorerViewController.h"
#import "FLEXObjectExplorerFactory.h"
#import "FLEXNetworkHistoryTableViewController.h"
typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
FLEXExplorerModeDefault,
@@ -367,21 +368,12 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
- (void)selectButtonTapped:(FLEXToolbarItem *)sender
{
if (self.currentMode == FLEXExplorerModeSelect) {
self.currentMode = FLEXExplorerModeDefault;
} else {
self.currentMode = FLEXExplorerModeSelect;
}
[self toggleSelectTool];
}
- (void)hierarchyButtonTapped:(FLEXToolbarItem *)sender
{
NSArray *allViews = [self allViewsInHierarchy];
NSDictionary *depthsForViews = [self hierarchyDepthsForViews:allViews];
FLEXHierarchyTableViewController *hierarchyTVC = [[FLEXHierarchyTableViewController alloc] initWithViews:allViews viewsAtTap:self.viewsAtTapPoint selectedView:self.selectedView depths:depthsForViews];
hierarchyTVC.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:hierarchyTVC];
[self makeKeyAndPresentViewController:navigationController animated:YES completion:nil];
[self toggleViewsTool];
}
- (NSArray *)allViewsInHierarchy
@@ -427,20 +419,12 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
- (void)moveButtonTapped:(FLEXToolbarItem *)sender
{
if (self.currentMode == FLEXExplorerModeMove) {
self.currentMode = FLEXExplorerModeDefault;
} else {
self.currentMode = FLEXExplorerModeMove;
}
[self toggleMoveTool];
}
- (void)globalsButtonTapped:(FLEXToolbarItem *)sender
{
FLEXGlobalsTableViewController *globalsViewController = [[FLEXGlobalsTableViewController alloc] init];
globalsViewController.delegate = self;
[FLEXGlobalsTableViewController setApplicationWindow:[[UIApplication sharedApplication] keyWindow]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:globalsViewController];
[self makeKeyAndPresentViewController:navigationController animated:YES completion:nil];
[self toggleMenuTool];
}
- (void)closeButtonTapped:(FLEXToolbarItem *)sender
@@ -830,4 +814,103 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
return self.previousKeyWindow != nil;
}
#pragma mark - Keyboard Shortcut Helpers
- (void)toggleSelectTool
{
if (self.currentMode == FLEXExplorerModeSelect) {
self.currentMode = FLEXExplorerModeDefault;
} else {
self.currentMode = FLEXExplorerModeSelect;
}
}
- (void)toggleMoveTool
{
if (self.currentMode == FLEXExplorerModeMove) {
self.currentMode = FLEXExplorerModeDefault;
} else {
self.currentMode = FLEXExplorerModeMove;
}
}
- (void)toggleViewsTool
{
BOOL viewsModalShown = [[self presentedViewController] isKindOfClass:[UINavigationController class]];
viewsModalShown = viewsModalShown && [[[(UINavigationController *)[self presentedViewController] viewControllers] firstObject] isKindOfClass:[FLEXHierarchyTableViewController class]];
if (viewsModalShown) {
[self resignKeyAndDismissViewControllerAnimated:YES completion:nil];
} else {
[self resignKeyAndDismissViewControllerAnimated:NO completion:nil];
NSArray *allViews = [self allViewsInHierarchy];
NSDictionary *depthsForViews = [self hierarchyDepthsForViews:allViews];
FLEXHierarchyTableViewController *hierarchyTVC = [[FLEXHierarchyTableViewController alloc] initWithViews:allViews viewsAtTap:self.viewsAtTapPoint selectedView:self.selectedView depths:depthsForViews];
hierarchyTVC.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:hierarchyTVC];
[self makeKeyAndPresentViewController:navigationController animated:YES completion:nil];
}
}
- (void)toggleMenuTool
{
BOOL menuModalShown = [[self presentedViewController] isKindOfClass:[UINavigationController class]];
menuModalShown = menuModalShown && [[[(UINavigationController *)[self presentedViewController] viewControllers] firstObject] isKindOfClass:[FLEXGlobalsTableViewController class]];
if (menuModalShown) {
[self resignKeyAndDismissViewControllerAnimated:YES completion:nil];
} else {
[self resignKeyAndDismissViewControllerAnimated:NO completion:nil];
FLEXGlobalsTableViewController *globalsViewController = [[FLEXGlobalsTableViewController alloc] init];
globalsViewController.delegate = self;
[FLEXGlobalsTableViewController setApplicationWindow:[[UIApplication sharedApplication] keyWindow]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:globalsViewController];
[self makeKeyAndPresentViewController:navigationController animated:YES completion:nil];
}
}
- (void)handleDownArrowKeyPressed
{
if (self.currentMode == FLEXExplorerModeMove) {
CGRect frame = self.selectedView.frame;
frame.origin.y += 1.0 / [[UIScreen mainScreen] scale];
self.selectedView.frame = frame;
} else if (self.currentMode == FLEXExplorerModeSelect && [self.viewsAtTapPoint count] > 0) {
NSInteger selectedViewIndex = [self.viewsAtTapPoint indexOfObject:self.selectedView];
if (selectedViewIndex > 0) {
self.selectedView = [self.viewsAtTapPoint objectAtIndex:selectedViewIndex - 1];
}
}
}
- (void)handleUpArrowKeyPressed
{
if (self.currentMode == FLEXExplorerModeMove) {
CGRect frame = self.selectedView.frame;
frame.origin.y -= 1.0 / [[UIScreen mainScreen] scale];
self.selectedView.frame = frame;
} else if (self.currentMode == FLEXExplorerModeSelect && [self.viewsAtTapPoint count] > 0) {
NSInteger selectedViewIndex = [self.viewsAtTapPoint indexOfObject:self.selectedView];
if (selectedViewIndex < [self.viewsAtTapPoint count] - 1) {
self.selectedView = [self.viewsAtTapPoint objectAtIndex:selectedViewIndex + 1];
}
}
}
- (void)handleRightArrowKeyPressed
{
if (self.currentMode == FLEXExplorerModeMove) {
CGRect frame = self.selectedView.frame;
frame.origin.x += 1.0 / [[UIScreen mainScreen] scale];
self.selectedView.frame = frame;
}
}
- (void)handleLeftArrowKeyPressed
{
if (self.currentMode == FLEXExplorerModeMove) {
CGRect frame = self.selectedView.frame;
frame.origin.x -= 1.0 / [[UIScreen mainScreen] scale];
self.selectedView.frame = frame;
}
}
@end
+20 -1
View File
@@ -18,15 +18,34 @@
- (void)showExplorer;
- (void)hideExplorer;
#pragma mark - Network Debugging
/// If this property is set to YES, FLEX will swizzle NSURLConnection*Delegate and NSURLSession*Delegate methods
/// on classes that conform to the protocols. This allows you to view network activity history from the main FLEX menu.
/// Full responses are kept temporarily in a size limited cache and may be pruged under memory pressure.
@property (nonatomic, assign, getter=isNetworkDebuggingEnabled) BOOL networkDebuggingEnabled;
/// Defaults to 50 MB if never set. Values set here are presisted across launches of the app.
/// Defaults to 25 MB if never set. Values set here are presisted across launches of the app.
/// The response cache uses an NSCache, so it may purge prior to hitting the limit when the app is under memory pressure.
@property (nonatomic, assign) NSUInteger networkResponseCacheByteLimit;
#pragma mark - Keyboard Shortcuts
/// Simulator keyboard shortcuts are enabled by default.
/// The shortcuts will not fire when there is an active text field, text view, or other responder accepting key input.
/// You can disable keyboard shortcuts if you have existing keyboard shortcuts that conflict with FLEX, or if you like doing things the hard way ;)
/// Keyboard shortcuts are always disabled (and support is compiled out) in non-simulator builds
@property (nonatomic, assign) BOOL simulatorShortcutsEnabled;
/// Adds an action to run when the specified key & modifier combination is pressed
/// @param key A single character string matching a key on the keyboard
/// @param modifiers Modifier keys such as shift, command, or alt/option
/// @param action The block to run on the main thread when the key & modifier combination is recognized.
/// @param description Shown the the keyboard shortcut help menu, which is accessed via the '?' key.
/// @note The action block will be retained for the duration of the application. You may want to use weak references.
/// @note FLEX registers several default keyboard shortcuts. Use the '?' key to see a list of shortcuts.
- (void)registerSimulatorShortcutWithKey:(NSString *)key modifiers:(UIKeyModifierFlags)modifiers action:(dispatch_block_t)action description:(NSString *)description;
#pragma mark - Extensions
/// Adds an entry at the bottom of the list of Global State items. Call this method before this view controller is displayed.
+191
View File
@@ -14,6 +14,10 @@
#import "FLEXObjectExplorerViewController.h"
#import "FLEXNetworkObserver.h"
#import "FLEXNetworkRecorder.h"
#import "FLEXKeyboardShortcutManager.h"
#import "FLEXFileBrowserTableViewController.h"
#import "FLEXNetworkHistoryTableViewController.h"
#import "FLEXKeyboardHelpViewController.h"
@interface FLEXManager () <FLEXWindowEventDelegate, FLEXExplorerViewControllerDelegate>
@@ -125,6 +129,114 @@
[self hideExplorer];
}
#pragma mark - Simulator Shortcuts
- (void)registerSimulatorShortcutWithKey:(NSString *)key modifiers:(UIKeyModifierFlags)modifiers action:(dispatch_block_t)action description:(NSString *)description
{
# if TARGET_OS_SIMULATOR
[[FLEXKeyboardShortcutManager sharedManager] registerSimulatorShortcutWithKey:key modifiers:modifiers action:action description:description];
#endif
}
- (void)setSimulatorShortcutsEnabled:(BOOL)simulatorShortcutsEnabled
{
# if TARGET_OS_SIMULATOR
[[FLEXKeyboardShortcutManager sharedManager] setEnabled:simulatorShortcutsEnabled];
#endif
}
- (BOOL)simulatorShortcutsEnabled
{
# if TARGET_OS_SIMULATOR
return [[FLEXKeyboardShortcutManager sharedManager] isEnabled];
#else
return NO;
#endif
}
- (void)registerDefaultSimulatorShortcuts
{
[self registerSimulatorShortcutWithKey:@"f" modifiers:0 action:^{
if ([self isHidden]) {
[self showExplorer];
} else {
[self hideExplorer];
}
} description:@"Toggle FLEX toolbar"];
[self registerSimulatorShortcutWithKey:@"g" modifiers:0 action:^{
[self showExplorerIfNeeded];
[self.explorerViewController toggleMenuTool];
} description:@"Toggle FLEX globlas menu"];
[self registerSimulatorShortcutWithKey:@"v" modifiers:0 action:^{
[self showExplorerIfNeeded];
[self.explorerViewController toggleViewsTool];
} description:@"Toggle view hierarchy menu"];
[self registerSimulatorShortcutWithKey:@"s" modifiers:0 action:^{
[self showExplorerIfNeeded];
[self.explorerViewController toggleSelectTool];
} description:@"Toggle select tool"];
[self registerSimulatorShortcutWithKey:@"m" modifiers:0 action:^{
[self showExplorerIfNeeded];
[self.explorerViewController toggleMoveTool];
} description:@"Toggle move tool"];
[self registerSimulatorShortcutWithKey:@"n" modifiers:0 action:^{
[self toggleTopViewControllerOfClass:[FLEXNetworkHistoryTableViewController class]];
} description:@"Toggle network history view"];
[self registerSimulatorShortcutWithKey:UIKeyInputDownArrow modifiers:0 action:^{
if ([self isHidden]) {
[self tryScrollDown];
} else {
[self.explorerViewController handleDownArrowKeyPressed];
}
} description:@"Cycle view selection\n\t\tMove view down\n\t\tScroll down"];
[self registerSimulatorShortcutWithKey:UIKeyInputUpArrow modifiers:0 action:^{
if ([self isHidden]) {
[self tryScrollUp];
} else {
[self.explorerViewController handleUpArrowKeyPressed];
}
} description:@"Cycle view selection\n\t\tMove view up\n\t\tScroll up"];
[self registerSimulatorShortcutWithKey:UIKeyInputRightArrow modifiers:0 action:^{
if (![self isHidden]) {
[self.explorerViewController handleRightArrowKeyPressed];
}
} description:@"Move selected view right"];
[self registerSimulatorShortcutWithKey:UIKeyInputLeftArrow modifiers:0 action:^{
if ([self isHidden]) {
[self tryGoBack];
} else {
[self.explorerViewController handleLeftArrowKeyPressed];
}
} description:@"Move selected view left"];
[self registerSimulatorShortcutWithKey:@"?" modifiers:0 action:^{
[self toggleTopViewControllerOfClass:[FLEXKeyboardHelpViewController class]];
} description:@"Toggle (this) help menu"];
[self registerSimulatorShortcutWithKey:UIKeyInputEscape modifiers:0 action:^{
[[[self topViewController] presentingViewController] dismissViewControllerAnimated:YES completion:nil];
} description:@"End editing text\n\t\tDismiss top view controller"];
[self registerSimulatorShortcutWithKey:@"o" modifiers:UIKeyModifierCommand|UIKeyModifierShift action:^{
[self toggleTopViewControllerOfClass:[FLEXFileBrowserTableViewController class]];
} description:@"Toggle file browser menu"];
}
+ (void)load
{
dispatch_async(dispatch_get_main_queue(), ^{
[[[self class] sharedManager] registerDefaultSimulatorShortcuts];
});
}
#pragma mark - Extensions
@@ -162,4 +274,83 @@
[self.userGlobalEntries addObject:entry];
}
- (void)tryScrollDown
{
UIScrollView *firstScrollView = [self firstScrollView];
CGPoint contentOffset = [firstScrollView contentOffset];
CGFloat distance = floor(firstScrollView.frame.size.height / 2.0);
CGFloat maxContentOffsetY = firstScrollView.contentSize.height + firstScrollView.contentInset.bottom - firstScrollView.frame.size.height;
distance = MIN(maxContentOffsetY - firstScrollView.contentOffset.y, distance);
contentOffset.y += distance;
[firstScrollView setContentOffset:contentOffset animated:YES];
}
- (void)tryScrollUp
{
UIScrollView *firstScrollView = [self firstScrollView];
CGPoint contentOffset = [firstScrollView contentOffset];
CGFloat distance = floor(firstScrollView.frame.size.height / 2.0);
CGFloat minContentOffsetY = -firstScrollView.contentInset.top;
distance = MIN(firstScrollView.contentOffset.y - minContentOffsetY, distance);
contentOffset.y -= distance;
[firstScrollView setContentOffset:contentOffset animated:YES];
}
- (UIScrollView *)firstScrollView
{
NSMutableArray *views = [[[[UIApplication sharedApplication] keyWindow] subviews] mutableCopy];
UIScrollView *scrollView = nil;
while ([views count] > 0) {
UIView *view = [views firstObject];
[views removeObjectAtIndex:0];
if ([view isKindOfClass:[UIScrollView class]]) {
scrollView = (UIScrollView *)view;
break;
} else {
[views addObjectsFromArray:[view subviews]];
}
}
return scrollView;
}
- (void)tryGoBack
{
UINavigationController *navigationController = nil;
UIViewController *topViewController = [self topViewController];
if ([topViewController isKindOfClass:[UINavigationController class]]) {
navigationController = (UINavigationController *)topViewController;
} else {
navigationController = topViewController.navigationController;
}
[navigationController popViewControllerAnimated:YES];
}
- (UIViewController *)topViewController
{
UIViewController *topViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
while ([topViewController presentedViewController]) {
topViewController = [topViewController presentedViewController];
}
return topViewController;
}
- (void)toggleTopViewControllerOfClass:(Class)class
{
UIViewController *topViewController = [self topViewController];
if ([topViewController isKindOfClass:[UINavigationController class]] && [[[(UINavigationController *)topViewController viewControllers] firstObject] isKindOfClass:[class class]]) {
[[topViewController presentingViewController] dismissViewControllerAnimated:YES completion:nil];
} else {
id viewController = [[class alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[topViewController presentViewController:navigationController animated:YES completion:nil];
}
}
- (void)showExplorerIfNeeded
{
if ([self isHidden]) {
[self showExplorer];
}
}
@end
@@ -39,9 +39,6 @@
UITableViewCell *networkDebuggingCell = [self switchCellWithTitle:@"Network Debugging" toggleAction:@selector(networkDebuggingToggled:) isOn:[FLEXNetworkObserver isEnabled]];
[mutableCells addObject:networkDebuggingCell];
UITableViewCell *enableOnLaunchCell = [self switchCellWithTitle:@"Enable on Launch" toggleAction:@selector(enableOnLaunchToggled:) isOn:[FLEXNetworkObserver shouldEnableOnLaunch]];
[mutableCells addObject:enableOnLaunchCell];
UITableViewCell *cacheMediaResponsesCell = [self switchCellWithTitle:@"Cache Media Responses" toggleAction:@selector(cacheMediaResponsesToggled:) isOn:NO];
[mutableCells addObject:cacheMediaResponsesCell];
@@ -64,11 +61,6 @@
[FLEXNetworkObserver setEnabled:sender.isOn];
}
- (void)enableOnLaunchToggled:(UISwitch *)sender
{
[FLEXNetworkObserver setShouldEnableOnLaunch:sender.isOn];
}
- (void)cacheMediaResponsesToggled:(UISwitch *)sender
{
[[FLEXNetworkRecorder defaultRecorder] setShouldCacheMediaResponses:sender.isOn];
@@ -22,12 +22,8 @@ extern NSString *const kFLEXNetworkObserverEnabledStateChangedNotification;
/// Swizzling occurs when the observer is enabled for the first time.
/// This reduces the impact of FLEX if network debugging is not desired.
/// NOTE: this setting persists between launches of the app.
+ (void)setEnabled:(BOOL)enabled;
+ (BOOL)isEnabled;
/// The enable on launch setting is persisted accross launches of the app.
/// If YES, the observer will automatically enable itself early in the application lifecycle.
+ (void)setShouldEnableOnLaunch:(BOOL)shouldEnableOnLaunch;
+ (BOOL)shouldEnableOnLaunch;
@end
@@ -14,13 +14,14 @@
#import "FLEXNetworkObserver.h"
#import "FLEXNetworkRecorder.h"
#import "FLEXUtility.h"
#import <objc/runtime.h>
#import <objc/message.h>
#import <dispatch/queue.h>
NSString *const kFLEXNetworkObserverEnabledStateChangedNotification = @"kFLEXNetworkObserverEnabledStateChangedNotification";
static NSString *const kFLEXNetworkObserverEnableOnLaunchDefaultsKey = @"com.flex.FLEXNetworkObserver.enableOnLaunch";
static NSString *const kFLEXNetworkObserverEnabledDefaultsKey = @"com.flex.FLEXNetworkObserver.enableOnLaunch";
typedef void (^NSURLSessionAsyncCompletion)(id fileURLOrData, NSURLResponse *response, NSError *error);
@@ -67,7 +68,6 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
@interface FLEXNetworkObserver ()
@property (nonatomic, assign, getter=isEnabled) BOOL enabled;
@property (nonatomic, strong) NSMutableDictionary *requestStatesForRequestIDs;
@property (nonatomic, strong) dispatch_queue_t queue;
@@ -79,43 +79,32 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
+ (void)setEnabled:(BOOL)enabled
{
BOOL previouslyEnabled = [self isEnabled];
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:kFLEXNetworkObserverEnabledDefaultsKey];
if (enabled) {
// Inject if needed. This injection is protected with a dispatch_once, so we're ok calling it multiple times.
// By doing the injection lazily, we keep the impact of the tool lower when this feature isn't enabled.
[self injectIntoAllNSURLConnectionDelegateClasses];
}
[[self sharedObserver] setEnabled:enabled];
}
+ (BOOL)isEnabled
{
return [[self sharedObserver] isEnabled];
}
- (void)setEnabled:(BOOL)enabled
{
if (_enabled != enabled) {
_enabled = enabled;
if (previouslyEnabled != enabled) {
[[NSNotificationCenter defaultCenter] postNotificationName:kFLEXNetworkObserverEnabledStateChangedNotification object:self];
}
}
+ (void)setShouldEnableOnLaunch:(BOOL)shouldEnableOnLaunch
+ (BOOL)isEnabled
{
[[NSUserDefaults standardUserDefaults] setBool:shouldEnableOnLaunch forKey:kFLEXNetworkObserverEnableOnLaunchDefaultsKey];
}
+ (BOOL)shouldEnableOnLaunch
{
return [[[NSUserDefaults standardUserDefaults] objectForKey:kFLEXNetworkObserverEnableOnLaunchDefaultsKey] boolValue];
return [[[NSUserDefaults standardUserDefaults] objectForKey:kFLEXNetworkObserverEnabledDefaultsKey] boolValue];
}
+ (void)load
{
// We don't want to do the swizzling from +load because not all the classes may be loaded at this point.
dispatch_async(dispatch_get_main_queue(), ^{
if ([self shouldEnableOnLaunch]) {
[self setEnabled:YES];
if ([self isEnabled]) {
[self injectIntoAllNSURLConnectionDelegateClasses];
}
});
}
@@ -139,11 +128,6 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
#pragma mark Delegate Injection Convenience Methods
+ (SEL)swizzledSelectorForSelector:(SEL)selector
{
return NSSelectorFromString([NSString stringWithFormat:@"_flex_swizzle_%x_%@", arc4random(), NSStringFromSelector(selector)]);
}
/// All swizzled delegate methods should make use of this guard.
/// This will prevent duplicated sniffing when the original implementation calls up to a superclass implementation which we've also swizzled.
/// The superclass implementation (and implementations in classes above that) will be executed without inteference if called from the original implementation.
@@ -170,66 +154,6 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
objc_setAssociatedObject(object, key, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
+ (BOOL)instanceRespondsButDoesNotImplementSelector:(SEL)selector class:(Class)cls
{
if ([cls instancesRespondToSelector:selector]) {
unsigned int numMethods = 0;
Method *methods = class_copyMethodList(cls, &numMethods);
BOOL implementsSelector = NO;
for (int index = 0; index < numMethods; index++) {
SEL methodSelector = method_getName(methods[index]);
if (selector == methodSelector) {
implementsSelector = YES;
break;
}
}
free(methods);
if (!implementsSelector) {
return YES;
}
}
return NO;
}
+ (void)replaceImplementationOfKnownSelector:(SEL)originalSelector onClass:(Class)class withBlock:(id)block swizzledSelector:(SEL)swizzledSelector
{
// This method is only intended for swizzling methods that are know to exist on the class.
// Bail if that isn't the case.
Method originalMethod = class_getInstanceMethod(class, originalSelector);
if (!originalMethod) {
return;
}
IMP implementation = imp_implementationWithBlock(block);
class_addMethod(class, swizzledSelector, implementation, method_getTypeEncoding(originalMethod));
Method newMethod = class_getInstanceMethod(class, swizzledSelector);
method_exchangeImplementations(originalMethod, newMethod);
}
+ (void)replaceImplementationOfSelector:(SEL)selector withSelector:(SEL)swizzledSelector forClass:(Class)cls withMethodDescription:(struct objc_method_description)methodDescription implementationBlock:(id)implementationBlock undefinedBlock:(id)undefinedBlock
{
if ([self instanceRespondsButDoesNotImplementSelector:selector class:cls]) {
return;
}
IMP implementation = imp_implementationWithBlock((id)([cls instancesRespondToSelector:selector] ? implementationBlock : undefinedBlock));
Method oldMethod = class_getInstanceMethod(cls, selector);
if (oldMethod) {
class_addMethod(cls, swizzledSelector, implementation, methodDescription.types);
Method newMethod = class_getInstanceMethod(cls, swizzledSelector);
method_exchangeImplementations(oldMethod, newMethod);
} else {
class_addMethod(cls, selector, implementation, methodDescription.types);
}
}
#pragma mark - Delegate Injection
+ (void)injectIntoAllNSURLConnectionDelegateClasses
@@ -333,7 +257,7 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
dispatch_once(&onceToken, ^{
Class class = [NSURLConnection class];
SEL selector = @selector(cancel);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Method originalCancel = class_getInstanceMethod(class, selector);
void (^swizzleBlock)(NSURLConnection *) = ^(NSURLConnection *slf) {
@@ -364,7 +288,7 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
class = NSClassFromString([@[@"__", @"NSC", @"FURLS", @"ession", @"Task"] componentsJoinedByString:@""]);
}
SEL selector = @selector(resume);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Method originalResume = class_getInstanceMethod(class, selector);
@@ -386,7 +310,7 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
dispatch_once(&onceToken, ^{
Class class = objc_getMetaClass(class_getName([NSURLConnection class]));
SEL selector = @selector(sendAsynchronousRequest:queue:completionHandler:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
typedef void (^NSURLConnectionAsyncCompletion)(NSURLResponse* response, NSData* data, NSError* connectionError);
@@ -416,7 +340,7 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}
};
[self replaceImplementationOfKnownSelector:selector onClass:class withBlock:asyncSwizzleBlock swizzledSelector:swizzledSelector];
[FLEXUtility replaceImplementationOfKnownSelector:selector onClass:class withBlock:asyncSwizzleBlock swizzledSelector:swizzledSelector];
});
}
@@ -426,7 +350,7 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
dispatch_once(&onceToken, ^{
Class class = objc_getMetaClass(class_getName([NSURLConnection class]));
SEL selector = @selector(sendSynchronousRequest:returningResponse:error:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
NSData *(^syncSwizzleBlock)(Class, NSURLRequest *, NSURLResponse **, NSError **) = ^NSData *(Class slf, NSURLRequest *request, NSURLResponse **response, NSError **error) {
NSData *data = nil;
@@ -458,7 +382,7 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
return data;
};
[self replaceImplementationOfKnownSelector:selector onClass:class withBlock:syncSwizzleBlock swizzledSelector:swizzledSelector];
[FLEXUtility replaceImplementationOfKnownSelector:selector onClass:class withBlock:syncSwizzleBlock swizzledSelector:swizzledSelector];
});
}
@@ -481,9 +405,9 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
for (int selectorIndex = 0; selectorIndex < numSelectors; selectorIndex++) {
SEL selector = selectors[selectorIndex];
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
if ([self instanceRespondsButDoesNotImplementSelector:selector class:class]) {
if ([FLEXUtility instanceRespondsButDoesNotImplementSelector:selector class:class]) {
// iOS 7 does not implement these methods on NSURLSession. We actually want to
// swizzle __NSCFURLSession, which we can get from the class of the shared session
class = [[NSURLSession sharedSession] class];
@@ -506,7 +430,7 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
return task;
};
[self replaceImplementationOfKnownSelector:selector onClass:class withBlock:asyncDataOrDownloadSwizzleBlock swizzledSelector:swizzledSelector];
[FLEXUtility replaceImplementationOfKnownSelector:selector onClass:class withBlock:asyncDataOrDownloadSwizzleBlock swizzledSelector:swizzledSelector];
}
});
}
@@ -528,9 +452,9 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
for (int selectorIndex = 0; selectorIndex < numSelectors; selectorIndex++) {
SEL selector = selectors[selectorIndex];
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
if ([self instanceRespondsButDoesNotImplementSelector:selector class:class]) {
if ([FLEXUtility instanceRespondsButDoesNotImplementSelector:selector class:class]) {
// iOS 7 does not implement these methods on NSURLSession. We actually want to
// swizzle __NSCFURLSession, which we can get from the class of the shared session
class = [[NSURLSession sharedSession] class];
@@ -550,7 +474,7 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
return task;
};
[self replaceImplementationOfKnownSelector:selector onClass:class withBlock:asyncUploadTaskSwizzleBlock swizzledSelector:swizzledSelector];
[FLEXUtility replaceImplementationOfKnownSelector:selector onClass:class withBlock:asyncUploadTaskSwizzleBlock swizzledSelector:swizzledSelector];
}
});
}
@@ -589,7 +513,7 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
+ (void)injectWillSendRequestIntoDelegateClass:(Class)cls
{
SEL selector = @selector(connection:willSendRequest:redirectResponse:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLConnectionDataDelegate);
if (!protocol) {
@@ -615,13 +539,13 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
return returnValue;
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectDidReceiveResponseIntoDelegateClass:(Class)cls
{
SEL selector = @selector(connection:didReceiveResponse:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLConnectionDataDelegate);
if (!protocol) {
@@ -644,13 +568,13 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectDidReceiveDataIntoDelegateClass:(Class)cls
{
SEL selector = @selector(connection:didReceiveData:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLConnectionDataDelegate);
if (!protocol) {
@@ -673,13 +597,13 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectDidFinishLoadingIntoDelegateClass:(Class)cls
{
SEL selector = @selector(connectionDidFinishLoading:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLConnectionDataDelegate);
if (!protocol) {
@@ -702,13 +626,13 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectDidFailWithErrorIntoDelegateClass:(Class)cls
{
SEL selector = @selector(connection:didFailWithError:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLConnectionDelegate);
struct objc_method_description methodDescription = protocol_getMethodDescription(protocol, selector, NO, YES);
@@ -727,13 +651,13 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectTaskWillPerformHTTPRedirectionIntoDelegateClass:(Class)cls
{
SEL selector = @selector(URLSession:task:willPerformHTTPRedirection:newRequest:completionHandler:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLSessionTaskDelegate);
@@ -753,14 +677,14 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectTaskDidReceiveDataIntoDelegateClass:(Class)cls
{
SEL selector = @selector(URLSession:dataTask:didReceiveData:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLSessionDataDelegate);
@@ -780,14 +704,14 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectDataTaskDidBecomeDownloadTaskIntoDelegateClass:(Class)cls
{
SEL selector = @selector(URLSession:dataTask:didBecomeDownloadTask:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLSessionDataDelegate);
@@ -807,13 +731,13 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectTaskDidReceiveResponseIntoDelegateClass:(Class)cls
{
SEL selector = @selector(URLSession:dataTask:didReceiveResponse:completionHandler:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLSessionDataDelegate);
@@ -833,14 +757,14 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectTaskDidCompleteWithErrorIntoDelegateClass:(Class)cls
{
SEL selector = @selector(URLSession:task:didCompleteWithError:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLSessionTaskDelegate);
struct objc_method_description methodDescription = protocol_getMethodDescription(protocol, selector, NO, YES);
@@ -859,14 +783,14 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
// Used for overriding AFNetworking behavior
+ (void)injectRespondsToSelectorIntoDelegateClass:(Class)cls
{
SEL selector = @selector(respondsToSelector:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
//Protocol *protocol = @protocol(NSURLSessionTaskDelegate);
Method method = class_getInstanceMethod(cls, selector);
@@ -883,14 +807,14 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
return ((BOOL(*)(id, SEL, SEL))objc_msgSend)(slf, swizzledSelector, sel);
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectDownloadTaskDidFinishDownloadingIntoDelegateClass:(Class)cls
{
SEL selector = @selector(URLSession:downloadTask:didFinishDownloadingToURL:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLSessionDownloadDelegate);
struct objc_method_description methodDescription = protocol_getMethodDescription(protocol, selector, NO, YES);
@@ -910,13 +834,13 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
+ (void)injectDownloadTaskDidWriteDataIntoDelegateClass:(Class)cls
{
SEL selector = @selector(URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:);
SEL swizzledSelector = [self swizzledSelectorForSelector:selector];
SEL swizzledSelector = [FLEXUtility swizzledSelectorForSelector:selector];
Protocol *protocol = @protocol(NSURLSessionDownloadDelegate);
struct objc_method_description methodDescription = protocol_getMethodDescription(protocol, selector, NO, YES);
@@ -935,7 +859,7 @@ didBecomeDownloadTask:(NSURLSessionDownloadTask *)downloadTask delegate:(id <NSU
}];
};
[self replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
[FLEXUtility replaceImplementationOfSelector:selector withSelector:swizzledSelector forClass:cls withMethodDescription:methodDescription implementationBlock:implementationBlock undefinedBlock:undefinedBlock];
}
@@ -972,7 +896,7 @@ static char const * const kFLEXRequestIDKey = "kFLEXRequestIDKey";
- (void)performBlock:(dispatch_block_t)block
{
if (self.isEnabled) {
if ([[self class] isEnabled]) {
dispatch_async(_queue, block);
}
}
@@ -0,0 +1,13 @@
//
// FLEXKeyboardHelpViewController.h
// UICatalog
//
// Created by Ryan Olson on 9/19/15.
// Copyright © 2015 f. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FLEXKeyboardHelpViewController : UIViewController
@end
@@ -0,0 +1,44 @@
//
// FLEXKeyboardHelpViewController.m
// UICatalog
//
// Created by Ryan Olson on 9/19/15.
// Copyright © 2015 f. All rights reserved.
//
#import "FLEXKeyboardHelpViewController.h"
#import "FLEXKeyboardShortcutManager.h"
@interface FLEXKeyboardHelpViewController ()
@property (nonatomic, strong) UITextView *textView;
@end
@implementation FLEXKeyboardHelpViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.textView = [[UITextView alloc] initWithFrame:self.view.bounds];
self.textView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.textView];
#if TARGET_OS_SIMULATOR
self.textView.text = [[FLEXKeyboardShortcutManager sharedManager] keyboardShortcutsDescription];
#endif
self.textView.backgroundColor = [UIColor blackColor];
self.textView.textColor = [UIColor whiteColor];
self.textView.font = [UIFont boldSystemFontOfSize:14.0];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.title = @"Simulator Shortcuts";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)];
}
- (void)donePressed:(id)sender
{
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
@end
@@ -0,0 +1,24 @@
//
// FLEXKeyboardShortcutManager.h
// FLEX
//
// Created by Ryan Olson on 9/19/15.
// Copyright © 2015 Flipboard. All rights reserved.
//
#import <UIKit/UIKit.h>
#if TARGET_OS_SIMULATOR
@interface FLEXKeyboardShortcutManager : NSObject
+ (instancetype)sharedManager;
- (void)registerSimulatorShortcutWithKey:(NSString *)key modifiers:(UIKeyModifierFlags)modifiers action:(dispatch_block_t)action description:(NSString *)description;
- (NSString *)keyboardShortcutsDescription;
@property (nonatomic, assign, getter=isEnabled) BOOL enabled;
@end
#endif
@@ -0,0 +1,243 @@
//
// FLEXKeyboardShortcutManager.m
// FLEX
//
// Created by Ryan Olson on 9/19/15.
// Copyright © 2015 Flipboard. All rights reserved.
//
#import "FLEXKeyboardShortcutManager.h"
#import "FLEXUtility.h"
#import <objc/runtime.h>
#import <objc/message.h>
#if TARGET_OS_SIMULATOR
@interface UIEvent (UIPhysicalKeyboardEvent)
@property (nonatomic, strong) NSString *_modifiedInput;
@property (nonatomic, strong) NSString *_unmodifiedInput;
@property (nonatomic, assign) UIKeyModifierFlags _modifierFlags;
@property (nonatomic, assign) BOOL _isKeyDown;
@end
@interface FLEXKeyInput : NSObject <NSCopying>
@property (nonatomic, copy, readonly) NSString *key;
@property (nonatomic, assign, readonly) UIKeyModifierFlags flags;
@property (nonatomic, copy, readonly) NSString *helpDescription;
@end
@implementation FLEXKeyInput
- (BOOL)isEqual:(id)object
{
BOOL isEqual = NO;
if ([object isKindOfClass:[FLEXKeyInput class]]) {
FLEXKeyInput *keyCommand = (FLEXKeyInput *)object;
BOOL equalKeys = self.key == keyCommand.key || [self.key isEqual:keyCommand.key];
BOOL equalFlags = self.flags == keyCommand.flags;
isEqual = equalKeys && equalFlags;
}
return isEqual;
}
- (NSUInteger)hash
{
return [self.key hash] ^ self.flags;
}
- (id)copyWithZone:(NSZone *)zone
{
return [[self class] keyInputForKey:self.key flags:self.flags helpDescription:self.helpDescription];
}
- (NSString *)description
{
NSDictionary *keyMappings = @{ UIKeyInputUpArrow : @"",
UIKeyInputDownArrow : @"",
UIKeyInputLeftArrow : @"",
UIKeyInputRightArrow : @"",
UIKeyInputEscape : @"",
@" " : @""};
NSString *prettyKey = nil;
if (self.key && [keyMappings objectForKey:self.key]) {
prettyKey = [keyMappings objectForKey:self.key];
} else {
prettyKey = [self.key uppercaseString];
}
NSString *prettyFlags = @"";
if (self.flags & UIKeyModifierControl) {
prettyFlags = [prettyFlags stringByAppendingString:@""];
}
if (self.flags & UIKeyModifierAlternate) {
prettyFlags = [prettyFlags stringByAppendingString:@""];
}
if (self.flags & UIKeyModifierShift) {
prettyFlags = [prettyFlags stringByAppendingString:@""];
}
if (self.flags & UIKeyModifierCommand) {
prettyFlags = [prettyFlags stringByAppendingString:@""];
}
// Fudging to get easy columns with tabs
if ([prettyFlags length] < 2) {
prettyKey = [prettyKey stringByAppendingString:@"\t"];
}
return [NSString stringWithFormat:@"%@%@\t%@", prettyFlags, prettyKey, self.helpDescription];
}
+ (instancetype)keyInputForKey:(NSString *)key flags:(UIKeyModifierFlags)flags
{
return [self keyInputForKey:key flags:flags helpDescription:nil];
}
+ (instancetype)keyInputForKey:(NSString *)key flags:(UIKeyModifierFlags)flags helpDescription:(NSString *)helpDescription
{
FLEXKeyInput *keyInput = [[self alloc] init];
if (keyInput) {
keyInput->_key = key;
keyInput->_flags = flags;
keyInput->_helpDescription = helpDescription;
}
return keyInput;
}
@end
@interface FLEXKeyboardShortcutManager ()
@property (nonatomic, strong) NSMutableDictionary *actionsForKeyInputs;
@end
@implementation FLEXKeyboardShortcutManager
+ (instancetype)sharedManager
{
static FLEXKeyboardShortcutManager *sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManager = [[[self class] alloc] init];
});
return sharedManager;
}
+ (void)load
{
SEL originalKeyEventSelector = NSSelectorFromString(@"handleKeyUIEvent:");
SEL swizzledKeyEventSelector = [FLEXUtility swizzledSelectorForSelector:originalKeyEventSelector];
void (^sendEventSwizzleBlock)(UIApplication *, UIEvent *) = ^(UIApplication *slf, UIEvent *event) {
[[[self class] sharedManager] handleKeyboardEvent:event];
((void(*)(id, SEL, id))objc_msgSend)(slf, swizzledKeyEventSelector, event);
};
[FLEXUtility replaceImplementationOfKnownSelector:originalKeyEventSelector onClass:[UIApplication class] withBlock:sendEventSwizzleBlock swizzledSelector:swizzledKeyEventSelector];
}
- (instancetype)init
{
self = [super init];
if (self) {
_actionsForKeyInputs = [NSMutableDictionary dictionary];
_enabled = YES;
}
return self;
}
- (void)registerSimulatorShortcutWithKey:(NSString *)key modifiers:(UIKeyModifierFlags)modifiers action:(dispatch_block_t)action description:(NSString *)description
{
FLEXKeyInput *keyInput = [FLEXKeyInput keyInputForKey:key flags:modifiers helpDescription:description];
[self.actionsForKeyInputs setObject:action forKey:keyInput];
}
- (void)handleKeyboardEvent:(UIEvent *)event
{
if (!self.enabled) {
return;
}
NSString *modifiedInput = nil;
NSString *unmodifiedInput = nil;
UIKeyModifierFlags flags = 0;
BOOL isKeyDown = NO;
if ([event respondsToSelector:@selector(_modifiedInput)]) {
modifiedInput = [event _modifiedInput];
}
if ([event respondsToSelector:@selector(_unmodifiedInput)]) {
unmodifiedInput = [event _unmodifiedInput];
}
if ([event respondsToSelector:@selector(_modifierFlags)]) {
flags = [event _modifierFlags];
}
if ([event respondsToSelector:@selector(_isKeyDown)]) {
isKeyDown = [event _isKeyDown];
}
BOOL interactionEnabled = ![[UIApplication sharedApplication] isIgnoringInteractionEvents];
if (isKeyDown && [modifiedInput length] > 0 && interactionEnabled) {
UIResponder *firstResponder = nil;
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
firstResponder = [window valueForKey:@"firstResponder"];
if (firstResponder) {
break;
}
}
// Ignore key commands (except escape) when there's an active responder
if (firstResponder) {
if ([unmodifiedInput isEqual:UIKeyInputEscape]) {
[firstResponder resignFirstResponder];
}
} else {
FLEXKeyInput *exactMatch = [FLEXKeyInput keyInputForKey:unmodifiedInput flags:flags];
dispatch_block_t actionBlock = [self.actionsForKeyInputs objectForKey:exactMatch];
if (!actionBlock) {
FLEXKeyInput *shiftMatch = [FLEXKeyInput keyInputForKey:modifiedInput flags:flags&(!UIKeyModifierShift)];
actionBlock = [self.actionsForKeyInputs objectForKey:shiftMatch];
}
if (!actionBlock) {
FLEXKeyInput *capitalMatch = [FLEXKeyInput keyInputForKey:[unmodifiedInput uppercaseString] flags:flags];
actionBlock = [self.actionsForKeyInputs objectForKey:capitalMatch];
}
if (actionBlock) {
actionBlock();
}
}
}
}
- (NSString *)keyboardShortcutsDescription
{
NSMutableString *description = [NSMutableString string];
NSArray *keyInputs = [[self.actionsForKeyInputs allKeys] sortedArrayUsingComparator:^NSComparisonResult(FLEXKeyInput *_Nonnull input1, FLEXKeyInput *_Nonnull input2) {
return [input1.key caseInsensitiveCompare:input2.key];
}];
for (FLEXKeyInput *keyInput in keyInputs) {
[description appendFormat:@"%@\n", keyInput];
}
return [description copy];
}
@end
#endif
+7
View File
@@ -38,4 +38,11 @@
+ (BOOL)isValidJSONData:(NSData *)data;
+ (NSData *)inflatedDataFromCompressedData:(NSData *)compressedData;
// Swizzling utilities
+ (SEL)swizzledSelectorForSelector:(SEL)selector;
+ (BOOL)instanceRespondsButDoesNotImplementSelector:(SEL)selector class:(Class)cls;
+ (void)replaceImplementationOfKnownSelector:(SEL)originalSelector onClass:(Class)class withBlock:(id)block swizzledSelector:(SEL)swizzledSelector;
+ (void)replaceImplementationOfSelector:(SEL)selector withSelector:(SEL)swizzledSelector forClass:(Class)cls withMethodDescription:(struct objc_method_description)methodDescription implementationBlock:(id)implementationBlock undefinedBlock:(id)undefinedBlock;
@end
+68 -2
View File
@@ -10,6 +10,7 @@
#import "FLEXResources.h"
#import <ImageIO/ImageIO.h>
#import <zlib.h>
#import <objc/runtime.h>
@implementation FLEXUtility
@@ -246,8 +247,8 @@
// [a, 1]
NSArray *components = [keyValueString componentsSeparatedByString:@"="];
if ([components count] == 2) {
NSString *key = [[components firstObject] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
id value = [[components lastObject] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *key = [[components firstObject] stringByRemovingPercentEncoding];
id value = [[components lastObject] stringByRemovingPercentEncoding];
// Handle multiple entries under the same key as an array
id existingEntry = [queryDictionary objectForKey:key];
@@ -325,4 +326,69 @@
return inflatedData;
}
+ (SEL)swizzledSelectorForSelector:(SEL)selector
{
return NSSelectorFromString([NSString stringWithFormat:@"_flex_swizzle_%x_%@", arc4random(), NSStringFromSelector(selector)]);
}
+ (BOOL)instanceRespondsButDoesNotImplementSelector:(SEL)selector class:(Class)cls
{
if ([cls instancesRespondToSelector:selector]) {
unsigned int numMethods = 0;
Method *methods = class_copyMethodList(cls, &numMethods);
BOOL implementsSelector = NO;
for (int index = 0; index < numMethods; index++) {
SEL methodSelector = method_getName(methods[index]);
if (selector == methodSelector) {
implementsSelector = YES;
break;
}
}
free(methods);
if (!implementsSelector) {
return YES;
}
}
return NO;
}
+ (void)replaceImplementationOfKnownSelector:(SEL)originalSelector onClass:(Class)class withBlock:(id)block swizzledSelector:(SEL)swizzledSelector
{
// This method is only intended for swizzling methods that are know to exist on the class.
// Bail if that isn't the case.
Method originalMethod = class_getInstanceMethod(class, originalSelector);
if (!originalMethod) {
return;
}
IMP implementation = imp_implementationWithBlock(block);
class_addMethod(class, swizzledSelector, implementation, method_getTypeEncoding(originalMethod));
Method newMethod = class_getInstanceMethod(class, swizzledSelector);
method_exchangeImplementations(originalMethod, newMethod);
}
+ (void)replaceImplementationOfSelector:(SEL)selector withSelector:(SEL)swizzledSelector forClass:(Class)cls withMethodDescription:(struct objc_method_description)methodDescription implementationBlock:(id)implementationBlock undefinedBlock:(id)undefinedBlock
{
if ([self instanceRespondsButDoesNotImplementSelector:selector class:cls]) {
return;
}
IMP implementation = imp_implementationWithBlock((id)([cls instancesRespondToSelector:selector] ? implementationBlock : undefinedBlock));
Method oldMethod = class_getInstanceMethod(cls, selector);
if (oldMethod) {
class_addMethod(cls, swizzledSelector, implementation, methodDescription.types);
Method newMethod = class_getInstanceMethod(cls, swizzledSelector);
method_exchangeImplementations(oldMethod, newMethod);
} else {
class_addMethod(cls, selector, implementation, methodDescription.types);
}
}
@end
@@ -52,6 +52,8 @@
9421B8911A8BBCB200BA3E46 /* FLEXNetworkTransactionTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 9421B8881A8BBCB200BA3E46 /* FLEXNetworkTransactionTableViewCell.m */; };
9421B8921A8BBCB200BA3E46 /* FLEXNetworkObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 9421B88B1A8BBCB200BA3E46 /* FLEXNetworkObserver.m */; };
9421B8931A8BBCB200BA3E46 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 9421B88C1A8BBCB200BA3E46 /* LICENSE */; };
942DCD8A1BAE131500DB5DC2 /* FLEXKeyboardShortcutManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 942DCD891BAE131500DB5DC2 /* FLEXKeyboardShortcutManager.m */; };
942DCD8D1BAE819500DB5DC2 /* FLEXKeyboardHelpViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 942DCD8C1BAE819500DB5DC2 /* FLEXKeyboardHelpViewController.m */; };
943203FE1978F42F00E24DB3 /* AAPLCatalogTableTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 943203FD1978F42F00E24DB3 /* AAPLCatalogTableTableViewController.m */; };
944F7489197B458C009AB039 /* FLEXArrayExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7426197B458C009AB039 /* FLEXArrayExplorerViewController.m */; };
944F748A197B458C009AB039 /* FLEXClassExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7428197B458C009AB039 /* FLEXClassExplorerViewController.m */; };
@@ -193,6 +195,10 @@
9421B88A1A8BBCB200BA3E46 /* FLEXNetworkObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXNetworkObserver.h; sourceTree = "<group>"; };
9421B88B1A8BBCB200BA3E46 /* FLEXNetworkObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXNetworkObserver.m; sourceTree = "<group>"; };
9421B88C1A8BBCB200BA3E46 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
942DCD881BAE131500DB5DC2 /* FLEXKeyboardShortcutManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXKeyboardShortcutManager.h; sourceTree = "<group>"; };
942DCD891BAE131500DB5DC2 /* FLEXKeyboardShortcutManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXKeyboardShortcutManager.m; sourceTree = "<group>"; };
942DCD8B1BAE819500DB5DC2 /* FLEXKeyboardHelpViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXKeyboardHelpViewController.h; sourceTree = "<group>"; };
942DCD8C1BAE819500DB5DC2 /* FLEXKeyboardHelpViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXKeyboardHelpViewController.m; sourceTree = "<group>"; };
943203FC1978F42F00E24DB3 /* AAPLCatalogTableTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AAPLCatalogTableTableViewController.h; sourceTree = "<group>"; };
943203FD1978F42F00E24DB3 /* AAPLCatalogTableTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AAPLCatalogTableTableViewController.m; sourceTree = "<group>"; };
944F7425197B458C009AB039 /* FLEXArrayExplorerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXArrayExplorerViewController.h; sourceTree = "<group>"; };
@@ -544,6 +550,10 @@
944F7443197B458C009AB039 /* FLEXUtility.m */,
94CB48371A8EC6000054A905 /* FLEXMultilineTableViewCell.h */,
94CB48381A8EC6000054A905 /* FLEXMultilineTableViewCell.m */,
942DCD881BAE131500DB5DC2 /* FLEXKeyboardShortcutManager.h */,
942DCD891BAE131500DB5DC2 /* FLEXKeyboardShortcutManager.m */,
942DCD8B1BAE819500DB5DC2 /* FLEXKeyboardHelpViewController.h */,
942DCD8C1BAE819500DB5DC2 /* FLEXKeyboardHelpViewController.m */,
);
name = Utility;
path = ../Classes/Utility;
@@ -772,6 +782,7 @@
944F74A2197B458C009AB039 /* FLEXArgumentInputViewFactory.m in Sources */,
944F74A1197B458C009AB039 /* FLEXArgumentInputView.m in Sources */,
535682B618F3670300BAAD62 /* AAPLSegmentedControlViewController.m in Sources */,
942DCD8A1BAE131500DB5DC2 /* FLEXKeyboardShortcutManager.m in Sources */,
944F74AE197B458C009AB039 /* FLEXClassesTableViewController.m in Sources */,
944F74B1197B458C009AB039 /* FLEXInstancesTableViewController.m in Sources */,
944F7497197B458C009AB039 /* FLEXUtility.m in Sources */,
@@ -817,6 +828,7 @@
944F74AB197B458C009AB039 /* FLEXManager.m in Sources */,
94C681F31A3E941800E1936D /* FLEXLayerExplorerViewController.m in Sources */,
944F74B2197B458C009AB039 /* FLEXLibrariesTableViewController.m in Sources */,
942DCD8D1BAE819500DB5DC2 /* FLEXKeyboardHelpViewController.m in Sources */,
535682BF18F3670300BAAD62 /* UIColor+AAPLApplicationSpecific.m in Sources */,
535682B718F3670300BAAD62 /* AAPLSliderViewController.m in Sources */,
9421B88E1A8BBCB200BA3E46 /* FLEXNetworkRecorder.m in Sources */,
+16
View File
@@ -136,6 +136,10 @@
3A4C95421B5B21410088C3F2 /* FLEXNetworkObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A4C94C21B5B21410088C3F2 /* FLEXNetworkObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
3A4C95431B5B21410088C3F2 /* FLEXNetworkObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A4C94C31B5B21410088C3F2 /* FLEXNetworkObserver.m */; };
3A4C95471B5B217D0088C3F2 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A4C95461B5B217D0088C3F2 /* libz.dylib */; };
942DCD871BAE0CA300DB5DC2 /* FLEXKeyboardShortcutManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 942DCD831BAE0AD300DB5DC2 /* FLEXKeyboardShortcutManager.m */; };
94AAF0381BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 94AAF0361BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.h */; settings = {ATTRIBUTES = (Private, ); }; };
94AAF0391BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94AAF0371BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.m */; };
94AAF03A1BAF2F0300DE8760 /* FLEXKeyboardShortcutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 942DCD821BAE0AD300DB5DC2 /* FLEXKeyboardShortcutManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -271,6 +275,10 @@
3A4C94C31B5B21410088C3F2 /* FLEXNetworkObserver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXNetworkObserver.m; sourceTree = "<group>"; };
3A4C94C41B5B21410088C3F2 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
3A4C95461B5B217D0088C3F2 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
942DCD821BAE0AD300DB5DC2 /* FLEXKeyboardShortcutManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXKeyboardShortcutManager.h; sourceTree = "<group>"; };
942DCD831BAE0AD300DB5DC2 /* FLEXKeyboardShortcutManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXKeyboardShortcutManager.m; sourceTree = "<group>"; };
94AAF0361BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXKeyboardHelpViewController.h; sourceTree = "<group>"; };
94AAF0371BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXKeyboardHelpViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -371,6 +379,10 @@
3A4C945C1B5B21410088C3F2 /* FLEXRuntimeUtility.m */,
3A4C945D1B5B21410088C3F2 /* FLEXUtility.h */,
3A4C945E1B5B21410088C3F2 /* FLEXUtility.m */,
942DCD821BAE0AD300DB5DC2 /* FLEXKeyboardShortcutManager.h */,
942DCD831BAE0AD300DB5DC2 /* FLEXKeyboardShortcutManager.m */,
94AAF0361BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.h */,
94AAF0371BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.m */,
);
path = Utility;
sourceTree = "<group>";
@@ -607,6 +619,8 @@
3A4C95421B5B21410088C3F2 /* FLEXNetworkObserver.h in Headers */,
3A4C95401B5B21410088C3F2 /* FLEXNetworkTransactionTableViewCell.h in Headers */,
3A4C95241B5B21410088C3F2 /* FLEXFileBrowserTableViewController.h in Headers */,
94AAF0381BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.h in Headers */,
94AAF03A1BAF2F0300DE8760 /* FLEXKeyboardShortcutManager.h in Headers */,
3A4C94E11B5B21410088C3F2 /* FLEXResources.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -679,6 +693,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
942DCD871BAE0CA300DB5DC2 /* FLEXKeyboardShortcutManager.m in Sources */,
3A4C95121B5B21410088C3F2 /* FLEXPropertyEditorViewController.m in Sources */,
3A4C95391B5B21410088C3F2 /* FLEXNetworkRecorder.m in Sources */,
3A4C950E1B5B21410088C3F2 /* FLEXIvarEditorViewController.m in Sources */,
@@ -686,6 +701,7 @@
3A4C94F61B5B21410088C3F2 /* FLEXArgumentInputJSONObjectView.m in Sources */,
3A4C94EC1B5B21410088C3F2 /* FLEXImagePreviewViewController.m in Sources */,
3A4C94F21B5B21410088C3F2 /* FLEXArgumentInputFontsPickerView.m in Sources */,
94AAF0391BAF2E1F00DE8760 /* FLEXKeyboardHelpViewController.m in Sources */,
3A4C951F1B5B21410088C3F2 /* FLEXClassesTableViewController.m in Sources */,
3A4C94C61B5B21410088C3F2 /* FLEXArrayExplorerViewController.m in Sources */,
3A4C95081B5B21410088C3F2 /* FLEXDefaultEditorViewController.m in Sources */,
+9
View File
@@ -17,6 +17,7 @@ FLEX (Flipboard Explorer) is a set of in-app debugging and exploration tools for
- Dynamically modify many properties and ivars.
- Dynamically call instance and class methods.
- Observe detailed network request history with timing, headers, and full responses.
- Add your own simulator keyboard shortcuts.
- View system log messages (e.g. from `NSLog`).
- Access any live object via a scan of the heap.
- View the file system within your app's sandbox.
@@ -28,6 +29,9 @@ Unlike many other debugging tools, FLEX runs entirely inside your app, so you do
## Usage
In the iOS simulator, you can use keyboard shortcuts to activate FLEX. `f` will toggle the FLEX toolbar. Hit the `?` key for a full list of shortcuts. You can also show FLEX programatically:
Short version:
```objc
@@ -71,6 +75,11 @@ FLEX queries malloc for all the live allocated memory blocks and searches for on
![Heap Exploration](http://engineering.flipboard.com/assets/flex/heap-browser.gif)
### Simulator Keyboard Shortcuts
Default keyboard shortcuts allow you to activate the FLEX tools, scroll with the arrow keys, and close modals using the escape key. You can also add custom keyboard shortcuts via `-[FLEXMananger registerSimulatorShortcutWithKey:modifiers:action:description]`
![Simulator Shortcuts](https://cloud.githubusercontent.com/assets/1422245/10002927/1106fd32-6067-11e5-8e21-57a357c259b6.png)
### File Browser
View the file system within your app's sandbox. FLEX shows file sizes, image previews, and pretty prints `.json` and `.plist` files. You can copy text and image files to the pasteboard if you want to inspect them outside of your app.