Skip to content

Commit

Permalink
fix(v2Adapter): 兼容更多老 SaaS 的属性值的类型
Browse files Browse the repository at this point in the history
  • Loading branch information
YoloMao committed Apr 16, 2024
1 parent 3ce88fc commit 5e86548
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
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

0 comments on commit 5e86548

Please sign in to comment.