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

fix(v2Adapter): 兼容更多老 SaaS 的属性值的类型 #307

Merged
merged 1 commit into from
Apr 23, 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
2 changes: 1 addition & 1 deletion Modules/V2Adapter/GrowingAutoTrackKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ - (void)growingImpTrack:(NSString *)eventId withNumber:(NSNumber *)number {
}

- (void)growingImpTrack:(NSString *)eventId withVariable:(NSDictionary<NSString *, id> *)variable {
variable = [GrowingV2Adapter fit3xDictionary:variable];
variable = [GrowingV2Adapter fitAttributes:variable];
[self growingTrackImpression:eventId attributes:variable];
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/V2AdapterTrackOnly/GrowingCoreKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ + (void)track:(NSString *)eventId withNumber:(NSNumber *)number {
}

+ (void)track:(NSString *)eventId withVariable:(NSDictionary<NSString *, NSObject *> *)variable {
variable = [GrowingV2Adapter fit3xDictionary:variable];
variable = [GrowingV2Adapter fitAttributes:variable];
id tracker = growing_getTracker();
if (!tracker) {
return;
Expand Down Expand Up @@ -145,7 +145,7 @@ + (void)clearUserId {
}

+ (void)setPeopleVariable:(NSDictionary<NSString *, NSObject *> *)variable {
variable = [GrowingV2Adapter fit3xDictionary:variable];
variable = [GrowingV2Adapter fitAttributes:variable];
id tracker = growing_getTracker();
if (!tracker) {
return;
Expand Down
17 changes: 12 additions & 5 deletions Modules/V2AdapterTrackOnly/GrowingV2Adapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,23 @@ + (void)upgrade {
[[GrowingPersistenceDataProvider sharedInstance] setString:@"1" forKey:kGrowingUserdefault_2xto3x];
}

+ (NSDictionary *)fit3xDictionary:(NSDictionary *)variable {
NSMutableDictionary *mutDic = [NSMutableDictionary dictionaryWithDictionary:variable];
+ (NSDictionary *)fitAttributes:(NSDictionary *)variable {
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
for (NSString *key in variable.allKeys) {
id obj = variable[key];
if ([obj isKindOfClass:[NSNumber class]]) {
if ([obj isKindOfClass:[NSString class]]) {
[dic setObject:obj forKey:key];
} else if ([obj isKindOfClass:[NSNumber class]]) {
NSString *value = ((NSNumber *)obj).stringValue;
[mutDic setValue:value forKey:key];
[dic setValue:value forKey:key];
} else if ([obj isKindOfClass:[NSNull class]]) {
[dic setObject:@"" forKey:key];
} else {
NSString *value = [obj description];
[dic setObject:value forKey:key];
}
}
return mutDic;
return [dic copy];
}

@end
2 changes: 1 addition & 1 deletion Modules/V2AdapterTrackOnly/Public/GrowingV2Adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
// 需要在初始化前调用, 将userId以及deviceId从v2版本迁移到v3版本中
+ (void)upgrade;

+ (NSDictionary *)fit3xDictionary:(NSDictionary *)variable;
+ (NSDictionary *)fitAttributes:(NSDictionary *)variable;

@end

Expand Down
Loading