From 7307d8db431c6cadcce0ce285cebf7455a457da2 Mon Sep 17 00:00:00 2001 From: Cristian Filipov Date: Thu, 15 Oct 2015 19:34:03 -0700 Subject: [PATCH] Update shortcut item on defaults change If the state is changed in any way other than via the shortcut (background app refresh, for example) the shortcut text will be out of sync with the actual state. --- GammaTest/AppDelegate.m | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/GammaTest/AppDelegate.m b/GammaTest/AppDelegate.m index e5a328b..00e0403 100644 --- a/GammaTest/AppDelegate.m +++ b/GammaTest/AppDelegate.m @@ -51,6 +51,9 @@ - (UIApplicationShortcutItem *)shortcutItemForCurrentState { - (void)updateShortCutItem { UIApplication *application = [UIApplication sharedApplication]; + if (![application respondsToSelector:@selector(shortcutItems)]) { + return; + } UIApplicationShortcutItem *shortcut = [self shortcutItemForCurrentState]; application.shortcutItems = @[shortcut]; } @@ -68,11 +71,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( @"autoEndHour": @7, @"autoEndMinute": @0, }]; - - if ([application respondsToSelector:@selector(shortcutItems)] && - !application.shortcutItems.count) { - [self updateShortCutItem]; - } + + [self updateShortCutItem]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(userDefaultsChanged:) + name:NSUserDefaultsDidChangeNotification + object:nil]; [GammaController autoChangeOrangenessIfNeeded]; @@ -143,4 +148,8 @@ - (void)application:(UIApplication *)application performActionForShortcutItem:(U completionHandler(handledShortCutItem); } +- (void)userDefaultsChanged:(NSNotification *)notification { + [self updateShortCutItem]; +} + @end