@@ -193,47 +193,59 @@ - (NSURLRequest *)dataRequest
193
193
}
194
194
}
195
195
196
- - (NSURLRequest *)displayRequest
197
- {
198
- NSString * queryString = [NSString stringWithFormat: @" %@ =%@ &%@ =%@ &%@ =%@ &%@ =%@ &%@ =%@ &%@ =%@ &%@ =%@ " ,
199
- kCountlyQSKeyAppKey , CountlyConnectionManager.sharedInstance.appKey.cly_URLEscaped,
200
- kCountlyQSKeyDeviceID , CountlyDeviceInfo.sharedInstance.deviceID.cly_URLEscaped,
201
- kCountlyQSKeySDKName , CountlyCommon.sharedInstance.SDKName,
202
- kCountlyQSKeySDKVersion , CountlyCommon.sharedInstance.SDKVersion,
203
- kCountlyFBKeyAppVersion , CountlyDeviceInfo.appVersion,
204
- kCountlyFBKeyPlatform , CountlyDeviceInfo.osName,
205
- kCountlyFBKeyWidgetID , self .ID];
196
+ - (NSURLRequest *)displayRequest {
197
+ // Create the base URL with endpoint and feedback type
198
+ NSMutableString *URL = [NSMutableString stringWithFormat: @" %@%@ /%@ " ,
199
+ CountlyConnectionManager.sharedInstance.host,
200
+ kCountlyEndpointFeedback ,
201
+ self .type];
206
202
207
- queryString = [queryString stringByAppendingFormat: @" &%@ =%@ " ,
208
- kCountlyAppVersionKey , CountlyDeviceInfo.appVersion];
203
+ // Create a dictionary for query parameters
204
+ NSDictionary *queryParams = @{
205
+ kCountlyQSKeyAppKey : CountlyConnectionManager.sharedInstance .appKey .cly_URLEscaped ,
206
+ kCountlyQSKeyDeviceID : CountlyDeviceInfo.sharedInstance .deviceID .cly_URLEscaped ,
207
+ kCountlyQSKeySDKName : CountlyCommon.sharedInstance .SDKName ,
208
+ kCountlyQSKeySDKVersion : CountlyCommon.sharedInstance .SDKVersion ,
209
+ kCountlyFBKeyAppVersion : CountlyDeviceInfo.appVersion ,
210
+ kCountlyFBKeyPlatform : CountlyDeviceInfo.osName ,
211
+ kCountlyFBKeyWidgetID : self.ID ,
212
+ kCountlyAppVersionKey : CountlyDeviceInfo.appVersion ,
213
+ };
209
214
215
+ // Create the query string
216
+ NSMutableArray *queryItems = [NSMutableArray array ];
217
+ [queryParams enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
218
+ [queryItems addObject: [NSString stringWithFormat: @" %@ =%@ " , key, obj]];
219
+ }];
220
+
221
+ NSString *queryString = [queryItems componentsJoinedByString: @" &" ];
222
+
223
+ // Append checksum to the query string
210
224
queryString = [CountlyConnectionManager.sharedInstance appendChecksum: queryString];
211
225
212
- NSMutableString * URL = CountlyConnectionManager.sharedInstance .host .mutableCopy ;
213
- [URL appendString: kCountlyEndpointFeedback ];
214
- NSString * feedbackTypeEndpoint = [@" /" stringByAppendingString: self .type];
215
- [URL appendString: feedbackTypeEndpoint];
226
+ // Add the query string to the URL
216
227
[URL appendFormat: @" ?%@ " , queryString];
217
228
218
- // customParams is an NSDictionary containing the custom key-value pairs
229
+ // Create custom parameters
219
230
NSDictionary *customParams = @{@" tc" : @" 1" };
220
231
221
- // Build custom parameter string
222
- NSMutableString *customString = [NSMutableString stringWithString: @" &custom=" ];
223
- [customString appendString: @" {" ];
224
- [customParams enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
225
- [customString appendFormat: @" \" %@ \" :%@ ," , key, obj];
226
- }];
227
- [customString deleteCharactersInRange: NSMakeRange (customString.length - 1 , 1 )]; // Remove the last comma
228
- [customString appendString: @" }" ];
232
+ // Create JSON data from custom parameters
233
+ NSError *error;
234
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject: customParams options: 0 error: &error];
229
235
230
- // Append custom parameter
231
- [URL appendString: customString];
236
+ if (!jsonData) {
237
+ NSLog (@" Failed to serialize JSON: %@ " , error);
238
+ } else {
239
+ NSString *customString = [[NSString alloc ] initWithData: jsonData encoding: NSUTF8StringEncoding];
240
+ // Append the custom parameter to the URL
241
+ [URL appendFormat: @" &custom=%@ " , customString.cly_URLEscaped];
242
+ }
232
243
233
- NSURLRequest * request = [ NSURLRequest requestWithURL: [ NSURL URLWithString: URL]];
234
- return request ;
244
+ // Create and return the NSURLRequest
245
+ return [ NSURLRequest requestWithURL: [ NSURL URLWithString: URL]] ;
235
246
}
236
247
248
+
237
249
- (void )recordReservedEventForDismissing
238
250
{
239
251
[self recordReservedEventWithSegmentation: @{kCountlyFBKeyClosed : @1 }];
0 commit comments