Skip to content

Commit

Permalink
Optimize display request method
Browse files Browse the repository at this point in the history
  • Loading branch information
ijunaid committed Oct 22, 2024
1 parent b459fe3 commit 952a6f8
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions CountlyFeedbackWidget.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,46 +174,61 @@ - (NSURLRequest *)dataRequest
}
}

- (NSURLRequest *)displayRequest
{
NSString* queryString = [NSString stringWithFormat:@"%@=%@&%@=%@&%@=%@&%@=%@&%@=%@&%@=%@&%@=%@",
kCountlyQSKeyAppKey, CountlyConnectionManager.sharedInstance.appKey.cly_URLEscaped,
kCountlyQSKeyDeviceID, CountlyDeviceInfo.sharedInstance.deviceID.cly_URLEscaped,
kCountlyQSKeySDKName, CountlyCommon.sharedInstance.SDKName,
kCountlyQSKeySDKVersion, CountlyCommon.sharedInstance.SDKVersion,
kCountlyFBKeyAppVersion, CountlyDeviceInfo.appVersion,
kCountlyFBKeyPlatform, CountlyDeviceInfo.osName,
kCountlyFBKeyWidgetID, self.ID];
- (NSURLRequest *)displayRequest {
// Create the base URL with endpoint and feedback type
NSMutableString *URL = [NSMutableString stringWithFormat:@"%@%@/%@",
CountlyConnectionManager.sharedInstance.host,
kCountlyEndpointFeedback,
self.type];

queryString = [queryString stringByAppendingFormat:@"&%@=%@",
kCountlyAppVersionKey, CountlyDeviceInfo.appVersion];
// Create a dictionary for query parameters
NSDictionary *queryParams = @{
kCountlyQSKeyAppKey: CountlyConnectionManager.sharedInstance.appKey.cly_URLEscaped,
kCountlyQSKeyDeviceID: CountlyDeviceInfo.sharedInstance.deviceID.cly_URLEscaped,
kCountlyQSKeySDKName: CountlyCommon.sharedInstance.SDKName,
kCountlyQSKeySDKVersion: CountlyCommon.sharedInstance.SDKVersion,
kCountlyFBKeyAppVersion: CountlyDeviceInfo.appVersion,
kCountlyFBKeyPlatform: CountlyDeviceInfo.osName,
kCountlyFBKeyWidgetID: self.ID,
kCountlyAppVersionKey: CountlyDeviceInfo.appVersion,
};

// Create the query string
NSMutableArray *queryItems = [NSMutableArray array];
[queryParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[queryItems addObject:[NSString stringWithFormat:@"%@=%@", key, obj]];
}];

NSString *queryString = [queryItems componentsJoinedByString:@"&"];

// Append checksum to the query string
queryString = [CountlyConnectionManager.sharedInstance appendChecksum:queryString];

NSMutableString* URL = CountlyConnectionManager.sharedInstance.host.mutableCopy;
[URL appendString:kCountlyEndpointFeedback];
NSString* feedbackTypeEndpoint = [@"/" stringByAppendingString:self.type];
[URL appendString:feedbackTypeEndpoint];
// Add the query string to the URL
[URL appendFormat:@"?%@", queryString];

// customParams is an NSDictionary containing the custom key-value pairs
NSDictionary *customParams = @{@"tc": @"1"};
// Create custom parameters
NSDictionary *customParams = @{@"tc": @"1",
@"rw": @"1",
@"xb": @"1"};

NSMutableString *customString = [NSMutableString new];
[customString appendString:@"{"];
[customParams enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[customString appendFormat:@"\"%@\":%@,", key, obj];
}];
[customString deleteCharactersInRange:NSMakeRange(customString.length - 1, 1)]; // Remove the last comma
[customString appendString:@"}"];
// Create JSON data from custom parameters
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:customParams options:0 error:&error];

// Append the custom parameter to the URL
[URL appendFormat:@"&custom=%@", customString.cly_URLEscaped];
if (!jsonData) {
NSLog(@"Failed to serialize JSON: %@", error);
} else {
NSString *customString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
// Append the custom parameter to the URL
[URL appendFormat:@"&custom=%@", customString.cly_URLEscaped];
}

NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:URL]];
return request;
// Create and return the NSURLRequest
return [NSURLRequest requestWithURL:[NSURL URLWithString:URL]];
}


- (void)recordReservedEventForDismissing
{
[self recordReservedEventWithSegmentation:@{kCountlyFBKeyClosed: @1}];
Expand Down

0 comments on commit 952a6f8

Please sign in to comment.