Skip to content

Instantly share code, notes, and snippets.

@shpakovski shpakovski/AppDelegate.m
Last active Aug 29, 2015

Embed
What would you like to do?
Custom window with re-activation gesture to show the Tweaks panel
#if FB_TWEAK_ENABLED
#import "CustomTweakWindow.h"
#endif
- (UIWindow *)newRootWindow
{
#if FB_TWEAK_ENABLED
NSString *windowClassName = @"CustomTweakWindow";
#else
NSString *windowClassName = @"UIWindow";
#endif
UIWindow *window = [(UIWindow *)[NSClassFromString(windowClassName) alloc] initWithFrame:[UIScreen mainScreen].bounds];
window.opaque = YES;
window.backgroundColor = [UIColor blackColor];
return window;
}
#import "FBTweakStore.h"
#import "FBTweakViewController.h"
@interface CustomTweakWindow () <FBTweakViewControllerDelegate> // Private
@property (nonatomic) NSDate *resignDate;
@end
#pragma mark
@implementation CustomTweakWindow
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark
- (void)applicationWillResignActive:(NSNotification *)notification
{
self.resignDate = [NSDate date];
}
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
if (self.resignDate == nil) return;
NSTimeInterval since = [[NSDate date] timeIntervalSinceDate:self.resignDate];
if (since < 1.0) // Re-active after 1 second to show the Tweaks panel
[self presentTweaks];
self.resignDate = nil;
}
#pragma mark
- (void)presentTweaks
{
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) return;
UIViewController *visibleViewController = self.rootViewController;
while (visibleViewController.presentedViewController != nil)
visibleViewController = visibleViewController.presentedViewController;
// Prevent double-presenting the tweaks view controller.
if (![visibleViewController isKindOfClass:[FBTweakViewController class]]) {
FBTweakStore *store = [FBTweakStore sharedInstance];
FBTweakViewController *viewController = [[FBTweakViewController alloc] initWithStore:store];
viewController.tweaksDelegate = self;
[visibleViewController presentViewController:viewController animated:YES completion:nil];
}
}
#pragma mark - FBTweakViewControllerDelegate
- (void)tweakViewControllerPressedDone:(FBTweakViewController *)tweakViewController
{
[tweakViewController dismissViewControllerAnimated:YES completion:nil];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.