Skip to content

Commit 9dce0ea

Browse files
authored
Merge pull request #315 from Countly/ios_changes
fix: add iOS changes
2 parents bbc327e + d987a13 commit 9dce0ea

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

ios/Classes/CountlyiOS/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
* Mitigated an issue where visibility could have been wrongly assigned if a view was closed while going to background. (Experimental!)
55
* Mitigated an issue where the user provided URLSessionConfiguration was not applied to direct requests
6+
* Mitigated an issue where a concurrent modification error could have happen when starting multiple stopped views
67
* Mitigated an issue that parsing internal content event segmentation.
78

89
## 24.7.7

ios/Classes/CountlyiOS/CountlyConnectionManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ extern const NSInteger kCountlyGETRequestMaxLength;
6969
- (NSString *)queryEssentials;
7070
- (NSString *)appendChecksum:(NSString *)queryString;
7171

72+
- (BOOL)isSessionStarted;
73+
7274
@end

ios/Classes/CountlyiOS/CountlyConnectionManager.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ @interface CountlyConnectionManager ()
1616
@property (nonatomic) NSURLSession* URLSession;
1717

1818
@property (nonatomic, strong) NSDate *startTime;
19+
1920
@end
2021

2122
NSString* const kCountlyQSKeyAppKey = @"app_key";
@@ -105,6 +106,11 @@ - (instancetype)init
105106
return self;
106107
}
107108

109+
110+
- (BOOL)isSessionStarted {
111+
return isSessionStarted;
112+
}
113+
108114
- (void)resetInstance {
109115
CLY_LOG_I(@"%s", __FUNCTION__);
110116
onceToken = 0;

ios/Classes/CountlyiOS/CountlyViewTrackingInternal.m

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ - (NSString*)startViewInternal:(NSString *)viewName customSegmentation:(NSDictio
436436
segmentation[kCountlyVTKeySegment] = CountlyDeviceInfo.osName;
437437
segmentation[kCountlyVTKeyVisit] = @1;
438438

439-
if (self.isFirstView)
439+
if (self.isFirstView && [CountlyConnectionManager.sharedInstance isSessionStarted])
440440
{
441441
self.isFirstView = NO;
442442
segmentation[kCountlyVTKeyStart] = @1;
@@ -545,27 +545,33 @@ - (void)startStoppedViewsInternal
545545
{
546546
// Create an array to store keys for views that need to be removed
547547
NSMutableArray<NSString *> *keysToRemove = [NSMutableArray array];
548-
548+
NSMutableArray<NSString *> *keysToStart = [NSMutableArray array];
549+
550+
// Collect keys without modifying the dictionary
549551
[self.viewDataDictionary enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, CountlyViewData * _Nonnull viewData, BOOL * _Nonnull stop) {
550552
if (viewData.willStartAgain)
551553
{
552-
NSString *viewID = [self startViewInternal:viewData.viewName customSegmentation:viewData.startSegmentation isAutoStoppedView:viewData.isAutoStoppedView];
553-
554-
// Retrieve the newly created viewData for the viewID
555-
CountlyViewData* viewDataNew = self.viewDataDictionary[viewID];
556-
557-
// Copy the segmentation data from the old view to the new view
558-
viewDataNew.segmentation = viewData.segmentation.mutableCopy;
559-
560-
// Add the old view's ID to the array for removal later
554+
[keysToStart addObject:key];
561555
[keysToRemove addObject:viewData.viewID];
562556
}
563557
}];
564558

559+
// Start the collected views after enumeration
560+
for (NSString *key in keysToStart)
561+
{
562+
CountlyViewData *viewData = self.viewDataDictionary[key];
563+
NSString *viewID = [self startViewInternal:viewData.viewName customSegmentation:viewData.startSegmentation isAutoStoppedView:viewData.isAutoStoppedView];
564+
565+
// Retrieve and update the newly created viewData
566+
CountlyViewData *viewDataNew = self.viewDataDictionary[viewID];
567+
viewDataNew.segmentation = viewData.segmentation.mutableCopy;
568+
}
569+
565570
// Remove the entries from the dictionary
566571
[self.viewDataDictionary removeObjectsForKeys:keysToRemove];
567572
}
568573

574+
569575
- (void)stopAllViewsInternal:(NSDictionary *)segmentation
570576
{
571577
// TODO: Should apply all the segmenation operations here at one place instead of doing it for individual view
@@ -759,7 +765,7 @@ - (void)applicationWillTerminate {
759765

760766
- (void)resetFirstView
761767
{
762-
self.isFirstView = NO;
768+
self.isFirstView = YES;
763769
}
764770

765771

0 commit comments

Comments
 (0)