From 4837359471bb7c55d685dcd626eceb41cec1de67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Fri, 8 May 2015 12:52:08 -0700 Subject: [PATCH] Register default user defaults on class initialization `-[MGLMapboxEvents init]` only gets called if `-[MGLMapboxEvents sharedManager]` sees that user defaults call for an `MGLMapboxEvents` to be created. But those user defaults were only being registered inside `-[MGLMapboxEvents init]`. This change moves the registration to `+initialize`, which is called as soon as the class is loaded. --- platform/ios/MGLMapboxEvents.m | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/platform/ios/MGLMapboxEvents.m b/platform/ios/MGLMapboxEvents.m index 3a6559b76..7890a7f53 100644 --- a/platform/ios/MGLMapboxEvents.m +++ b/platform/ios/MGLMapboxEvents.m @@ -109,15 +109,9 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; @implementation MGLMapboxEvents -// Must be called from the main thread. Only called internally. -// -- (instancetype) init { - MGLAssertIsMainThread(); - - self = [super init]; - if (self) { - - // Put Settings bundle into memory ++ (void)initialize { + if (self == [MGLMapboxEvents class]) { + // Register defaults from DefaultValue entries in Settings.bundle plist. NSString *appSettingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"]; if(!appSettingsBundle) { NSLog(@"Could not find Settings.bundle"); @@ -136,6 +130,16 @@ NSString *const MGLEventGestureRotateStart = @"Rotation"; [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister]; } + } +} + +// Must be called from the main thread. Only called internally. +// +- (instancetype) init { + MGLAssertIsMainThread(); + + self = [super init]; + if (self) { _appBundleId = [[NSBundle mainBundle] bundleIdentifier]; NSString *uniqueID = [[NSProcessInfo processInfo] globallyUniqueString]; _serialQueue = dispatch_queue_create([[NSString stringWithFormat:@"%@.%@.events.serial", _appBundleId, uniqueID] UTF8String], DISPATCH_QUEUE_SERIAL);