Skip to content

Commit

Permalink
Release 3.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
zhujg-00 committed Sep 26, 2021
1 parent 617690b commit 5aafbde
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 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 = "3.1.8"
s.version = "3.1.9"
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
8 changes: 8 additions & 0 deletions SensorsAnalyticsSDK/AutoTrack/AppClick/UIView+AutoTrack.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ - (NSString *)sensorsdata_elementContent {
return content;
}
}

if ([self isKindOfClass:NSClassFromString(@"WXView")]) { // WEEX 元素,http://doc.weex.io/zh/docs/components/a.html
NSString *content = [self.accessibilityValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (content.length > 0) {
return content;
}
}

if ([[self nextResponder] isKindOfClass:UITextField.class] && ![self isKindOfClass:UIButton.class]) {
/* 兼容输入框的元素采集
UITextField 本身是一个容器,包括 UITextField 的元素内容,文字是直接渲染到 view 的
Expand Down
2 changes: 0 additions & 2 deletions SensorsAnalyticsSDK/Core/SAConfigOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ - (instancetype)initWithServerURL:(NSString *)serverURL launchOptions:(id)launch
_minRequestHourInterval = 24;
_maxRequestHourInterval = 48;

_flushBeforeEnterBackground = YES;

#ifdef SENSORS_ANALYTICS_ENABLE_AUTOTRACK_CHILD_VIEWSCREEN
_enableAutoTrackChildViewScreen = YES;
#endif
Expand Down
9 changes: 5 additions & 4 deletions SensorsAnalyticsSDK/Core/SensorsAnalyticsSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#import "SAProfileEventObject.h"
#import "SAJSONUtil.h"

#define VERSION @"3.1.8"
#define VERSION @"3.1.9"

void *SensorsAnalyticsQueueTag = &SensorsAnalyticsQueueTag;

Expand Down Expand Up @@ -462,9 +462,10 @@ - (void)appLifecycleStateDidChange:(NSNotification *)sender {

dispatch_async(self.serialQueue, ^{
// 上传所有的数据
[self.eventTracker flushAllEventRecords];
// 结束后台任务
endBackgroundTask();
[self.eventTracker flushAllEventRecordsWithCompletion:^{
// 结束后台任务
endBackgroundTask();
}];
});
#else
dispatch_async(self.serialQueue, ^{
Expand Down
1 change: 1 addition & 0 deletions SensorsAnalyticsSDK/Core/Tracker/SAEventTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern NSUInteger const SAEventFlushRecordSize;
- (void)trackEvent:(NSDictionary *)event isSignUp:(BOOL)isSignUp;

- (void)flushAllEventRecords;
- (void)flushAllEventRecordsWithCompletion:(void(^ _Nullable)(void))completion;

@end

Expand Down
22 changes: 19 additions & 3 deletions SensorsAnalyticsSDK/Core/Tracker/SAEventTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,33 @@ - (BOOL)canFlush {
}

- (void)flushAllEventRecords {
[self flushAllEventRecordsWithCompletion:nil];
}

- (void)flushAllEventRecordsWithCompletion:(void(^)(void))completion {
if (![self canFlush]) {
if (completion) {
completion();
}
return;
}
[self flushRecordsWithSize:self.isDebugMode ? 1 : 50 repeatCount:kSAFlushMaxRepeatCount];
[self flushRecordsWithSize:self.isDebugMode ? 1 : 50 repeatCount:kSAFlushMaxRepeatCount completion:completion];
}

- (void)flushRecordsWithSize:(NSUInteger)size repeatCount:(NSInteger)repeatCount {
- (void)flushRecordsWithSize:(NSUInteger)size repeatCount:(NSInteger)repeatCount completion:(void(^)(void))completion {
// 防止在数据量过大时, 递归 flush, 导致堆栈溢出崩溃; 因此需要限制递归次数
if (repeatCount <= 0) {
if (completion) {
completion();
}
return;
}
// 从数据库中查询数据
NSArray<SAEventRecord *> *records = [self.eventStore selectRecords:size];
if (records.count == 0) {
if (completion) {
completion();
}
return;
}

Expand All @@ -156,11 +169,14 @@ - (void)flushRecordsWithSize:(NSUInteger)size repeatCount:(NSInteger)repeatCount
void(^block)(void) = ^ {
if (!success) {
[strongSelf.eventStore updateRecords:recordIDs status:SAEventRecordStatusNone];
if (completion) {
completion();
}
return;
}
// 5. 删除数据
if ([strongSelf.eventStore deleteRecords:recordIDs]) {
[strongSelf flushRecordsWithSize:size repeatCount:repeatCount - 1];
[strongSelf flushRecordsWithSize:size repeatCount:repeatCount - 1 completion:completion];
}
};
if (sensorsdata_is_same_queue(strongSelf.queue)) {
Expand Down

0 comments on commit 5aafbde

Please sign in to comment.