Skip to content

Commit

Permalink
Merge pull request #362 from Countly/view-iteration-issue-from-jsama
Browse files Browse the repository at this point in the history
Concurrent Modification Fix
  • Loading branch information
turtledreams authored Nov 21, 2024
2 parents c89de85 + 68eec6a commit 22c056f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 24.7.8
* Mitigated an issue where visibility could have been wrongly assigned if a view was closed while going to background. (Experimental!)
* Mitigated an issue where the user provided URLSessionConfiguration was not applied to direct requests
* Mitigated an issue where a concurrent modification error could have happen when starting multiple stopped views

## 24.7.7
* Changed the visibility tracking segmentation values to binary
Expand Down
26 changes: 16 additions & 10 deletions CountlyViewTrackingInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -545,27 +545,33 @@ - (void)startStoppedViewsInternal
{
// Create an array to store keys for views that need to be removed
NSMutableArray<NSString *> *keysToRemove = [NSMutableArray array];

NSMutableArray<NSString *> *keysToStart = [NSMutableArray array];

// Collect keys without modifying the dictionary
[self.viewDataDictionary enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, CountlyViewData * _Nonnull viewData, BOOL * _Nonnull stop) {
if (viewData.willStartAgain)
{
NSString *viewID = [self startViewInternal:viewData.viewName customSegmentation:viewData.startSegmentation isAutoStoppedView:viewData.isAutoStoppedView];

// Retrieve the newly created viewData for the viewID
CountlyViewData* viewDataNew = self.viewDataDictionary[viewID];

// Copy the segmentation data from the old view to the new view
viewDataNew.segmentation = viewData.segmentation.mutableCopy;

// Add the old view's ID to the array for removal later
[keysToStart addObject:key];
[keysToRemove addObject:viewData.viewID];
}
}];

// Start the collected views after enumeration
for (NSString *key in keysToStart)
{
CountlyViewData *viewData = self.viewDataDictionary[key];
NSString *viewID = [self startViewInternal:viewData.viewName customSegmentation:viewData.startSegmentation isAutoStoppedView:viewData.isAutoStoppedView];

// Retrieve and update the newly created viewData
CountlyViewData *viewDataNew = self.viewDataDictionary[viewID];
viewDataNew.segmentation = viewData.segmentation.mutableCopy;
}

// Remove the entries from the dictionary
[self.viewDataDictionary removeObjectsForKeys:keysToRemove];
}


- (void)stopAllViewsInternal:(NSDictionary *)segmentation
{
// TODO: Should apply all the segmenation operations here at one place instead of doing it for individual view
Expand Down

0 comments on commit 22c056f

Please sign in to comment.