|
// feature keys |
|
#define kFeatureA @"FeatureA" |
|
|
|
// Ground Control keys |
|
#define GROUND_CONTROL_URL @"http://yourserver.com/gc.php?version=%@&bundle=%@&lang=%@" |
|
#define kGroundControlLastCheck @"GroundControlLastCheck" |
|
#define kGroundControlCheckInterval @"GroundControlCheckInterval" |
|
|
|
@implementation LocationsAppDelegate { |
|
BOOL _isFeatureAEnabled; // Example feature |
|
|
|
NSDate *_groundControlLastCheck; |
|
NSUInteger _groundControlCheckInterval; |
|
} |
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { |
|
... |
|
// default check interval in days |
|
_groundControlCheckInterval = 7; |
|
[self initializeGroundControl]; |
|
... |
|
} |
|
|
|
- (void)applicationWillEnterForeground:(UIApplication *)application { |
|
... |
|
[self initializeGroundControl]; |
|
... |
|
} |
|
|
|
|
|
#pragma mark - Ground Control |
|
|
|
- (BOOL)shouldUpdateGroundControlData { |
|
BOOL checkForUpdate = NO; |
|
|
|
if ([[NSUserDefaults standardUserDefaults] objectForKey:kGroundControlLastCheck]) { |
|
_groundControlLastCheck = [[NSUserDefaults standardUserDefaults] objectForKey:kGroundControlLastCheck]; |
|
} |
|
|
|
if (!_groundControlLastCheck) { |
|
_groundControlLastCheck = [NSDate distantPast]; |
|
} |
|
|
|
NSString *testValue = nil; |
|
testValue = [[NSUserDefaults standardUserDefaults] stringForKey:kGroundControlCheckInterval]; |
|
if (testValue != nil) { |
|
_groundControlCheckInterval = [[NSUserDefaults standardUserDefaults] integerForKey:kGroundControlCheckInterval]; |
|
} |
|
|
|
NSTimeInterval dateDiff = fabs([_groundControlLastCheck timeIntervalSinceNow]); |
|
if (dateDiff != 0) |
|
dateDiff = dateDiff / (60*60*24); |
|
|
|
checkForUpdate = (dateDiff >= _groundControlCheckInterval); |
|
|
|
#if defined (CONFIGURATION_Debug) |
|
// we always tun this check on startup, because we want to test, right? |
|
checkForUpdate = YES; |
|
#endif |
|
|
|
return checkForUpdate; |
|
} |
|
|
|
- (void)updateGroundControlFeatures { |
|
// update the remotely configurable features |
|
|
|
NSString *testValue = nil; |
|
|
|
// example feature |
|
testValue = [[NSUserDefaults standardUserDefaults] stringForKey:kFeatureA]; |
|
if (testValue != nil) { |
|
_isFeatureAEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:kFeatureA]; |
|
// now you would somehow react on the change of this value or use the other approaches described in Ground Control docs |
|
} |
|
|
|
// ground control check interval in days, app default is set to 7 |
|
testValue = [[NSUserDefaults standardUserDefaults] stringForKey:kGroundControlCheckInterval]; |
|
if (testValue != nil) { |
|
_groundControlCheckInterval = [[NSUserDefaults standardUserDefaults] integerForKey:kGroundControlCheckInterval]; |
|
} |
|
} |
|
|
|
- (void)initializeGroundControl { |
|
[self updateGroundControlFeatures]; |
|
|
|
if (![self shouldUpdateGroundControlData]) return; |
|
|
|
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]; |
|
NSString *bundle = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"]; |
|
NSString *language = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]; |
|
NSString *urlString = [NSString stringWithFormat:GROUND_CONTROL_URL, version, bundle, language]; |
|
NSURL *url = [NSURL URLWithString:urlString]; |
|
[[NSUserDefaults standardUserDefaults] registerDefaultsWithURL:url |
|
success:^(NSDictionary *defaults) { |
|
_groundControlLastCheck = [NSDate date]; |
|
[[NSUserDefaults standardUserDefaults] setObject:_groundControlLastCheck forKey:kGroundControlLastCheck]; |
|
|
|
[self updateGroundControlFeatures]; |
|
} |
|
failure:^(NSError *error) { |
|
}]; |
|
} |
|
|