diff --git a/CountlyFeedbackWidget.m b/CountlyFeedbackWidget.m index 560ac471..e1af46e1 100644 --- a/CountlyFeedbackWidget.m +++ b/CountlyFeedbackWidget.m @@ -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}];