Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content response changes #345

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions CountlyContentBuilderInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,23 @@ - (void)fetchContents {
return;
}

NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSString *pathToHtml = jsonResponse[@"pathToHtml"];
NSDictionary *placementCoordinates = jsonResponse[@"placementCoordinates"];
NSError *jsonError;
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];

if (jsonError) {
CLY_LOG_I(@"Failed to parse JSON: %@", jsonError);
self->_isRequestQueueLocked = NO;
return;
}

if (!jsonResponse) {
CLY_LOG_I(@"Received empty or null response.");
self->_isRequestQueueLocked = NO;
return;
}

NSString *pathToHtml = jsonResponse[@"html"];
NSDictionary *placementCoordinates = jsonResponse[@"geo"];
if(pathToHtml) {
[self showContentWithHtmlPath:pathToHtml placementCoordinates:placementCoordinates];
}
Expand All @@ -118,9 +132,8 @@ - (NSURLRequest *)fetchContentsRequest
{
NSString* queryString = [CountlyConnectionManager.sharedInstance queryEssentials];
NSString *resolutionJson = [self resolutionJson];
queryString = [queryString stringByAppendingFormat:@"&%@=%@&%@=%@",
kCountlyQSKeyMethod, kCountlyCBFetchContent,
@"res", resolutionJson];
queryString = [queryString stringByAppendingFormat:@"&%@=%@",
@"resolution", resolutionJson];

queryString = [CountlyConnectionManager.sharedInstance appendChecksum:queryString];

Expand Down Expand Up @@ -155,8 +168,8 @@ - (NSString *)resolutionJson {
CGFloat height = screenBounds.size.height;

NSDictionary *resolutionDict = @{
@"p": @{@"h": @(height), @"w": @(width)},
@"l": @{@"h": @(width), @"w": @(height)}
@"portrait": @{@"height": @(height), @"width": @(width)},
@"landscape": @{@"height": @(width), @"width": @(height)}
};

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:resolutionDict options:0 error:nil];
Expand All @@ -180,12 +193,12 @@ - (void)showContentWithHtmlPath:(NSString *)urlString placementCoordinates:(NSDi


// Get the appropriate coordinates based on the orientation
NSDictionary *coordinates = isLandscape ? placementCoordinates[@"landscape"] : placementCoordinates[@"portrait"];
NSDictionary *coordinates = isLandscape ? placementCoordinates[@"l"] : placementCoordinates[@"p"];

CGFloat x = [coordinates[@"x"] floatValue];
CGFloat y = [coordinates[@"y"] floatValue];
CGFloat width = [coordinates[@"width"] floatValue];
CGFloat height = [coordinates[@"height"] floatValue];
CGFloat width = [coordinates[@"w"] floatValue];
CGFloat height = [coordinates[@"h"] floatValue];

CGRect frame = CGRectMake(x, y, width, height);

Expand Down
16 changes: 10 additions & 6 deletions CountlyPersistency.m
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,27 @@ - (void)recordEvent:(CountlyEvent *)event

- (NSString *)serializedRecordedEvents
{
NSMutableArray* tempArray = NSMutableArray.new;

NSMutableArray *tempArray = NSMutableArray.new;
@synchronized (self.recordedEvents)
{
if (self.recordedEvents.count == 0)
return nil;

for (CountlyEvent* event in self.recordedEvents.copy)

NSArray *eventsCopy = self.recordedEvents.copy;

for (CountlyEvent *event in eventsCopy)
{
[tempArray addObject:[event dictionaryRepresentation]];
[self.recordedEvents removeObject:event];
}

[self.recordedEvents removeObjectsInArray:eventsCopy];
}

return [tempArray cly_JSONify];
}


- (void)flushEvents
{
@synchronized (self.recordedEvents)
Expand Down