Skip to content

Commit

Permalink
Merge pull request #348 from Countly/widget-url-fix
Browse files Browse the repository at this point in the history
Fixed feedback widget url encoding issue for custom string
  • Loading branch information
turtledreams authored Oct 24, 2024
2 parents 3ba6847 + 0199e24 commit e989e60
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 36 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## x.x.x
## 24.7.4
* Mitigated an issue with the feedback widget URL encoding on iOS 16 and earlier, which prevented the widget from displaying
* Mitigated an issue with content fetch URL encoding on iOS 16 and earlier, which caused the request to fail

* Added `CountlyFeedbacks:` interface with new view methods (Access with `Countly.sharedInstance.feedback`):
* Method to present feedback widget (wih an optional widget selector(name, ID or tag) string and a Callback):
* `presentNPS`
Expand Down
2 changes: 1 addition & 1 deletion Countly-PL.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Countly-PL'
s.version = '24.7.3'
s.version = '24.7.4'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'Countly is an innovative, real-time, open source mobile analytics platform.'
s.homepage = 'https://github.com/Countly/countly-sdk-ios'
Expand Down
2 changes: 1 addition & 1 deletion Countly.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Countly'
s.version = '24.7.3'
s.version = '24.7.4'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = 'Countly is an innovative, real-time, open source mobile analytics platform.'
s.homepage = 'https://github.com/Countly/countly-sdk-ios'
Expand Down
4 changes: 2 additions & 2 deletions Countly.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 24.7.3;
MARKETING_VERSION = 24.7.4;
PRODUCT_BUNDLE_IDENTIFIER = ly.count.CountlyiOSSDK;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -766,7 +766,7 @@
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = 24.7.3;
MARKETING_VERSION = 24.7.4;
PRODUCT_BUNDLE_IDENTIFIER = ly.count.CountlyiOSSDK;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
2 changes: 1 addition & 1 deletion CountlyCommon.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ @interface CountlyCommon ()
#endif
@end

NSString* const kCountlySDKVersion = @"24.7.3";
NSString* const kCountlySDKVersion = @"24.7.4";
NSString* const kCountlySDKName = @"objc-native-ios";

NSString* const kCountlyErrorDomain = @"ly.count.ErrorDomain";
Expand Down
2 changes: 1 addition & 1 deletion CountlyContentBuilderInternal.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ - (NSURLRequest *)fetchContentsRequest
NSString* queryString = [CountlyConnectionManager.sharedInstance queryEssentials];
NSString *resolutionJson = [self resolutionJson];
queryString = [queryString stringByAppendingFormat:@"&%@=%@",
@"resolution", resolutionJson];
@"resolution", resolutionJson.cly_URLEscaped];

queryString = [CountlyConnectionManager.sharedInstance appendChecksum:queryString];

Expand Down
70 changes: 41 additions & 29 deletions CountlyFeedbackWidget.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,47 +193,59 @@ - (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
// Create custom parameters
NSDictionary *customParams = @{@"tc": @"1"};

// Build custom parameter string
NSMutableString *customString = [NSMutableString stringWithString:@"&custom="];
[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 custom parameter
[URL appendString:customString];
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 e989e60

Please sign in to comment.