Skip to content

Commit 84d0633

Browse files
authored
Merge pull request #398 from Countly/fix_sc
fix: sc reset
2 parents 5099cd8 + 2dcc8db commit 84d0633

File tree

8 files changed

+78
-22
lines changed

8 files changed

+78
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 25.4.3
2+
* Mitigated an issue where SDK behavior settings were set to default when fetching for new config.
3+
* Mitigated an issue where latest fetched behavior settings were replacing the current settings instead of merging.
4+
15
## 25.4.2
26
* Added fullscreen support for feedback widgets.
37
* Added "disableSDKBehaviorSettingsUpdates" init config parameter to disable server config updates.

Countly-PL.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Countly-PL'
3-
s.version = '25.4.2'
3+
s.version = '25.4.3'
44
s.license = { :type => 'MIT', :file => 'LICENSE' }
55
s.summary = 'Countly is an innovative, real-time, open source mobile analytics platform.'
66
s.homepage = 'https://github.com/Countly/countly-sdk-ios'

Countly.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Countly'
3-
s.version = '25.4.2'
3+
s.version = '25.4.3'
44
s.license = { :type => 'MIT', :file => 'LICENSE' }
55
s.summary = 'Countly is an innovative, real-time, open source mobile analytics platform.'
66
s.homepage = 'https://github.com/Countly/countly-sdk-ios'

Countly.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@
768768
"@loader_path/Frameworks",
769769
);
770770
MACOSX_DEPLOYMENT_TARGET = 10.14;
771-
MARKETING_VERSION = 25.4.2;
771+
MARKETING_VERSION = 25.4.3;
772772
PRODUCT_BUNDLE_IDENTIFIER = ly.count.CountlyiOSSDK;
773773
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
774774
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -800,7 +800,7 @@
800800
"@loader_path/Frameworks",
801801
);
802802
MACOSX_DEPLOYMENT_TARGET = 10.14;
803-
MARKETING_VERSION = 25.4.2;
803+
MARKETING_VERSION = 25.4.3;
804804
PRODUCT_BUNDLE_IDENTIFIER = ly.count.CountlyiOSSDK;
805805
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
806806
PROVISIONING_PROFILE_SPECIFIER = "";

CountlyCommon.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ @interface CountlyCommon ()
2929
#endif
3030
@end
3131

32-
NSString* const kCountlySDKVersion = @"25.4.2";
32+
NSString* const kCountlySDKVersion = @"25.4.3";
3333
NSString* const kCountlySDKName = @"objc-native-ios";
3434

3535
NSString* const kCountlyErrorDomain = @"ly.count.ErrorDomain";

CountlyPersistency.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
- (NSDictionary *)retrieveRemoteConfig;
5959
- (void)storeRemoteConfig:(NSDictionary *)remoteConfig;
6060

61-
- (NSDictionary *)retrieveServerConfig;
62-
- (void)storeServerConfig:(NSDictionary *)serverConfig;
61+
- (NSMutableDictionary *)retrieveServerConfig;
62+
- (void)storeServerConfig:(NSMutableDictionary *)serverConfig;
6363

6464
- (NSDictionary *)retrieveHealthCheckTrackerState;
6565
- (void)storeHealthCheckTrackerState:(NSDictionary *)healthCheckTrackerState;

CountlyPersistency.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,16 +593,17 @@ - (void)storeRemoteConfig:(NSDictionary *)remoteConfig
593593
[NSUserDefaults.standardUserDefaults synchronize];
594594
}
595595

596-
- (NSDictionary *)retrieveServerConfig
596+
- (NSMutableDictionary *)retrieveServerConfig
597597
{
598598
NSDictionary* serverConfig = [NSUserDefaults.standardUserDefaults objectForKey:kCountlyServerConfigPersistencyKey];
599-
if (!serverConfig)
600-
serverConfig = NSDictionary.new;
601-
602-
return serverConfig;
599+
if ([serverConfig isKindOfClass:[NSDictionary class]]) {
600+
return [serverConfig mutableCopy];
601+
}
602+
603+
return [NSMutableDictionary new];
603604
}
604605

605-
- (void)storeServerConfig:(NSDictionary *)serverConfig
606+
- (void)storeServerConfig:(NSMutableDictionary *)serverConfig
606607
{
607608
[NSUserDefaults.standardUserDefaults setObject:serverConfig forKey:kCountlyServerConfigPersistencyKey];
608609
[NSUserDefaults.standardUserDefaults synchronize];

CountlyServerConfig.m

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,66 @@ - (instancetype)init
116116

117117
- (void)retrieveServerConfigFromStorage:(NSString *)sdkBehaviorSettings
118118
{
119-
NSError *error = nil;
120-
NSDictionary *serverConfigObject = [CountlyPersistency.sharedInstance retrieveServerConfig];
121-
if (serverConfigObject.count == 0 && sdkBehaviorSettings)
119+
NSMutableDictionary *persistentBehaviorSettings = [CountlyPersistency.sharedInstance retrieveServerConfig];
120+
if (persistentBehaviorSettings.count == 0 && sdkBehaviorSettings)
122121
{
123-
serverConfigObject = [NSJSONSerialization JSONObjectWithData:[sdkBehaviorSettings cly_dataUTF8] options:0 error:&error];
122+
NSError *error = nil;
123+
id parsed = [NSJSONSerialization JSONObjectWithData:[sdkBehaviorSettings cly_dataUTF8] options:0 error:&error];
124+
125+
if ([parsed isKindOfClass:[NSDictionary class]]) {
126+
persistentBehaviorSettings = [(NSDictionary *)parsed mutableCopy];
127+
[CountlyPersistency.sharedInstance storeServerConfig:persistentBehaviorSettings];
128+
} else {
129+
CLY_LOG_W(@"%s, Failed to parse sdkBehaviorSettings or not a dictionary: %@", __FUNCTION__, error);
130+
}
124131
}
125132

126-
if (serverConfigObject.count > 0 && !error)
133+
[self populateServerConfig:persistentBehaviorSettings];
134+
}
135+
136+
- (void)mergeBehaviorSettings:(NSMutableDictionary *)baseConfig
137+
withConfig:(NSDictionary *)newConfig
138+
{
139+
// c, t and v paramters must exist
140+
if(newConfig.count != 3 || !newConfig[kRConfig]) {
141+
CLY_LOG_D(@"%s, missing entries for a behavior settings omitting", __FUNCTION__);
142+
return;
143+
}
144+
145+
if (!newConfig[kRVersion] || !newConfig[kRTimestamp])
127146
{
128-
[self populateServerConfig:serverConfigObject];
147+
CLY_LOG_D(@"%s, version or timestamp is missing in the behavioır settings omitting", __FUNCTION__);
148+
return;
149+
}
150+
151+
if(!([newConfig[kRConfig] isKindOfClass:[NSDictionary class]]) || ((NSDictionary *)newConfig[kRConfig]).count == 0){
152+
CLY_LOG_D(@"%s, invalid behavior settings omitting", __FUNCTION__);
153+
return;
154+
}
155+
156+
id timestamp = newConfig[kRTimestamp];
157+
if (timestamp) {
158+
baseConfig[kRTimestamp] = timestamp;
159+
}
160+
161+
id version = newConfig[kRVersion];
162+
if (version) {
163+
baseConfig[kRVersion] = version;
164+
}
165+
166+
NSDictionary *cBase = baseConfig[kRConfig] ?: NSMutableDictionary.new;
167+
NSDictionary *cNew = newConfig[kRConfig];
168+
169+
if ([cBase isKindOfClass:[NSDictionary class]] || [cNew isKindOfClass:[NSDictionary class]]) {
170+
NSMutableDictionary *cMerged = [cBase mutableCopy];
171+
172+
[cNew enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
173+
if (obj != nil && obj != [NSNull null]) {
174+
cMerged[key] = obj;
175+
}
176+
}];
177+
178+
baseConfig[kRConfig] = cMerged;
129179
}
130180
}
131181

@@ -379,9 +429,10 @@ - (void)fetchServerConfig:(CountlyConfig *)config
379429

380430
if (serverConfigResponse[kRConfig] != nil)
381431
{
382-
[CountlyPersistency.sharedInstance storeServerConfig:serverConfigResponse];
383-
[self setDefaultValues];
384-
[self populateServerConfig:serverConfigResponse];
432+
NSMutableDictionary *persistentBehaviorSettings = [CountlyPersistency.sharedInstance retrieveServerConfig];
433+
[self mergeBehaviorSettings:persistentBehaviorSettings withConfig:serverConfigResponse];
434+
[CountlyPersistency.sharedInstance storeServerConfig:persistentBehaviorSettings];
435+
[self populateServerConfig:persistentBehaviorSettings];
385436
}
386437

387438
[self notifySdkConfigChange:config]; // if no config let stored ones to be set

0 commit comments

Comments
 (0)