Skip to content

Commit

Permalink
Release 4.5.22
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoyue committed Nov 10, 2023
1 parent a951be2 commit e4a79ff
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SensorsAnalyticsSDK"
s.version = "4.5.21"
s.version = "4.5.22"
s.summary = "The official iOS SDK of Sensors Analytics."
s.homepage = "http://www.sensorsdata.cn"
s.source = { :git => 'https://github.com/sensorsdata/sa-sdk-ios.git', :tag => "v#{s.version}" }
Expand Down
24 changes: 13 additions & 11 deletions SensorsAnalyticsSDK/Core/Builder/EventObject/SABaseEventObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ - (instancetype)initWithH5Event:(NSDictionary *)event {
NSString *type = event[kSAEventType];
_type = [SABaseEventObject eventTypeWithType:type];
_lib = [[SAEventLibObject alloc] initWithH5Lib:event[kSAEventLib]];
_time = [[NSDate date] timeIntervalSince1970] * 1000;
_trackId = @(arc4random());
_currentSystemUpTime = NSProcessInfo.processInfo.systemUptime * 1000;

_ignoreRemoteConfig = NO;

_hybridH5 = YES;

// 优先使用 web 端时间,防止历史事件时间被改错
if ([event[kSAEventTime] isKindOfClass:NSNumber.class]) {
_time = [event[kSAEventTime] unsignedLongLongValue];
} else {
_time = [[NSDate date] timeIntervalSince1970] * 1000;
}
_eventId = event[kSAEventName];
_loginId = event[kSAEventLoginId];
_anonymousId = event[kSAEventAnonymousId];
Expand All @@ -72,21 +77,18 @@ - (instancetype)initWithH5Event:(NSDictionary *)event {
_token = properties[kSAEventToken];

id timeNumber = properties[kSAEventCommonOptionalPropertyTime];
if (timeNumber) { //包含 $time
NSNumber *customTime = nil;
if ([timeNumber isKindOfClass:[NSDate class]]) {
customTime = @([(NSDate *)timeNumber timeIntervalSince1970] * 1000);
} else if ([timeNumber isKindOfClass:[NSNumber class]]) {
customTime = timeNumber;
}
// $time 类型合法
if ([timeNumber isKindOfClass:[NSNumber class]]) {
NSNumber *customTime = timeNumber;

if (!customTime) {
SALogError(@"H5 $time '%@' invalid,Please check the value", timeNumber);
} else if ([customTime compare:@(kSAEventCommonOptionalPropertyTimeInt)] == NSOrderedAscending) {
if ([customTime compare:@(kSAEventCommonOptionalPropertyTimeInt)] == NSOrderedAscending) {
SALogError(@"H5 $time error %@,Please check the value", timeNumber);
} else {
_time = [customTime unsignedLongLongValue];
}
} else if (timeNumber) {
// $time 类型不合法
SALogError(@"H5 $time '%@' invalid,Please check the value", timeNumber);
}

[properties removeObjectsForKeys:@[@"_nocache", @"server_url", kSAAppVisualProperties, kSAEventProject, kSAEventToken, kSAEventCommonOptionalPropertyTime]];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ - (void)processWithInput:(SAFlowData *)input completion:(SAFlowDataCompletion)co
object.token = (NSString *)properties[kSAEventCommonOptionalPropertyToken];
id originalTime = properties[kSAEventCommonOptionalPropertyTime];

// App 内嵌 H5 自定义 time 在初始化中单独处理
if ([originalTime isKindOfClass:NSDate.class] && !object.hybridH5) {
// 如果公共属性设置 $time, H5 事件也需要修改
if ([originalTime isKindOfClass:NSDate.class]) {
NSDate *customTime = (NSDate *)originalTime;
int64_t customTimeInt = [customTime timeIntervalSince1970] * 1000;
if (customTimeInt >= kSAEventCommonOptionalPropertyTimeInt) {
object.time = customTimeInt;
} else {
SALogError(@"$time error %lld, Please check the value", customTimeInt);
}
} else if (originalTime && !object.hybridH5) {
} else if (originalTime) {
SALogError(@"$time '%@' invalid, Please check the value", originalTime);
}

Expand Down
5 changes: 2 additions & 3 deletions SensorsAnalyticsSDK/Core/SALogger/SAConsoleLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ - (NSString *)sensorsdata_unicodeString {
[mutableString appendString:@"\""];
NSData *data = [mutableString dataUsingEncoding:NSUTF8StringEncoding];

NSError *error = nil;
NSPropertyListFormat format = NSPropertyListOpenStepFormat;
NSString *formatString = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:&format error:&error];
return error ? self : [formatString stringByReplacingOccurrencesOfString:@"\\r\\n" withString:@"\n"];
NSString *formatString = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:&format error:NULL];
return (!formatString || ![formatString isKindOfClass:NSString.class]) ? self : [formatString stringByReplacingOccurrencesOfString:@"\\r\\n" withString:@"\n"];
}

@end
Expand Down
24 changes: 17 additions & 7 deletions SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#import "SALimitKeyManager.h"
#import "NSDictionary+SACopyProperties.h"

#define VERSION @"4.5.21"
#define VERSION @"4.5.22"

void *SensorsAnalyticsQueueTag = &SensorsAnalyticsQueueTag;

Expand Down Expand Up @@ -974,12 +974,22 @@ - (void)increment:(NSDictionary *)profileDict {
}

- (void)append:(NSString *)profile by:(NSObject<NSFastEnumeration> *)content {
if (profile && content) {
if ([content isKindOfClass:[NSSet class]] || [content isKindOfClass:[NSArray class]]) {
SAProfileAppendEventObject *object = [[SAProfileAppendEventObject alloc] initWithType:kSAProfileAppend];

[self trackEventObject:object properties:@{profile: content}];
}
if (!profile || !content) {
SALogWarn(@"content and profile cannot be empty, please check the value");
return;
}
if (![content isKindOfClass:NSArray.class] && ![content isKindOfClass:NSSet.class]) {
SALogWarn(@"content values should be NSArray or NSSet class, but current value: %@, with invalid type: %@", content, [content class]);
return;
}

SAProfileAppendEventObject *object = [[SAProfileAppendEventObject alloc] initWithType:kSAProfileAppend];
// 针对 NSArray 元素去重
if ([content isKindOfClass:NSArray.class]) {
NSSet *uniqueSet = [NSSet setWithArray:(NSArray *)content];
[self trackEventObject:object properties:@{profile: uniqueSet}];
} else {
[self trackEventObject:object properties:@{profile: content}];
}
}

Expand Down
4 changes: 4 additions & 0 deletions SensorsAnalyticsSDK/Location/SALocationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
static NSString * const kSAEventPresetPropertyLatitude = @"$latitude";
static NSString * const kSAEventPresetPropertyLongitude = @"$longitude";
static NSString * const kSAEventPresetPropertyCoordinateSystem = @"$geo_coordinate_system";

/* 国际通用的地球坐标系,CLLocationManager 采集定位输出结果是 WGS-84 坐标
国内地图,比如高德、腾讯等,因为国家的保密要求,使用的是偏移后 GCJ-02坐标,戏称“火星坐标”,和 WGS84 存在坐标偏差
*/
static NSString * const kSAAppleCoordinateSystem = @"WGS84";

@interface SALocationManager() <CLLocationManagerDelegate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) NSInteger level;

/// 元素平台
@property (nonatomic, assign) NSString *platform;
@property (nonatomic, copy) NSString *platform;

@end

Expand Down

0 comments on commit e4a79ff

Please sign in to comment.