Skip to content

Commit

Permalink
fix: debugEnabled 配置为 YES 时实时发送 event 数据
Browse files Browse the repository at this point in the history
  • Loading branch information
YoloMao committed Aug 10, 2021
1 parent 4671ef1 commit cfd27b5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
6 changes: 3 additions & 3 deletions GrowingTrackerCore/Event/Base/GrowingBaseEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ typedef NS_ENUM(NSUInteger, GrowingAppState) {
};

typedef NS_OPTIONS(NSUInteger, GrowingEventSendPolicy) {
GrowingEventSendPolicyInstant = 1 << 0,///实时发送
GrowingEventSendPolicyMobileData = 1 << 1,///移动网络流量发送
GrowingEventSendPolicyWIFI = 1 << 2,///wif情况下发送
GrowingEventSendPolicyInstant = 1 << 0, /// 实时发送(目前仅VISIT事件为实时发送策略)
GrowingEventSendPolicyMobileData = 1 << 1, /// 移动网络流量发送
GrowingEventSendPolicyWiFi = 1 << 2, /// 仅WiFi可发送(特殊事件数据,如大文件等)
};


Expand Down
2 changes: 1 addition & 1 deletion GrowingTrackerCore/Event/Base/GrowingBaseEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (instancetype)initWithBuilder:(GrowingBaseBuilder *)builder {
}

- (GrowingEventSendPolicy)sendPolicy {
return GrowingEventSendPolicyMobileData | GrowingEventSendPolicyWIFI;
return GrowingEventSendPolicyMobileData;
}

- (NSDictionary *)toDictionary {
Expand Down
22 changes: 15 additions & 7 deletions GrowingTrackerCore/Event/GrowingEventManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,20 @@ - (void)configChannels {
- (void)startTimerSend {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
BOOL debugEnabled = GrowingConfigurationManager.sharedInstance.trackConfiguration.debugEnabled;
if (debugEnabled) {
// send event instantly
return;
}

CGFloat configInterval = GrowingConfigurationManager.sharedInstance.trackConfiguration.dataUploadInterval;
CGFloat dataUploadInterval = MAX(configInterval, 5); // at least 5 seconds

dispatch_queue_t queue = dispatch_queue_create("io.growing", NULL);
dispatch_set_target_queue(queue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0));
self.reportTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
dispatch_source_set_timer(self.reportTimer,
dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 5), // first upload
dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * dataUploadInterval), // first upload
NSEC_PER_SEC * dataUploadInterval,
NSEC_PER_SEC * 1);
dispatch_source_set_event_handler(self.reportTimer, ^{
Expand Down Expand Up @@ -241,18 +247,19 @@ - (void)sendEventsOfChannel_unsafe:(GrowingEventChannel *)channel {
}
NSUInteger policyMask = GrowingEventSendPolicyInstant;
if ([GrowingNetworkInterfaceManager sharedInstance].WiFiValid) {
policyMask = GrowingEventSendPolicyInstant|GrowingEventSendPolicyMobileData|GrowingEventSendPolicyWIFI;
} else if ([GrowingNetworkInterfaceManager sharedInstance].WWANValid){
policyMask = GrowingEventSendPolicyInstant|GrowingEventSendPolicyMobileData;
policyMask = GrowingEventSendPolicyInstant | GrowingEventSendPolicyMobileData | GrowingEventSendPolicyWiFi;
} else if ([GrowingNetworkInterfaceManager sharedInstance].WWANValid) {
if (self.uploadEventSize < self.uploadLimitOfCellular) {
GIOLogDebug(@"Upload key data with mobile network (channel = %zd).",
[self.allEventChannels indexOfObject:channel]);
policyMask = GrowingEventSendPolicyInstant | GrowingEventSendPolicyMobileData;
isViaCellular = YES;
} else {
GIOLogDebug(@"Mobile network is forbidden. upload later (channel = %zd).",
[self.allEventChannels indexOfObject:channel]);
//实时发送策略无视流量限制
policyMask = GrowingEventSendPolicyInstant;;
policyMask = GrowingEventSendPolicyInstant;
}
}

Expand Down Expand Up @@ -358,7 +365,8 @@ - (void)writeToDatabaseWithEvent:(GrowingBaseEvent *)event {

[db setEvent:waitForPersist forKey:uuidString];

if (GrowingEventSendPolicyInstant & event.sendPolicy) { // send event instantly
BOOL debugEnabled = GrowingConfigurationManager.sharedInstance.trackConfiguration.debugEnabled;
if (GrowingEventSendPolicyInstant & event.sendPolicy || debugEnabled) { // send event instantly
[self sendEventsInstantWithChannel:eventChannel];
}
}
Expand Down Expand Up @@ -387,7 +395,7 @@ - (void)removeEvents_unsafe:(NSArray<__kindof GrowingEventPersistence *> *)event
}
}

- (NSArray<GrowingEventPersistence *> *)getEventsToBeUploadUnsafe:(GrowingEventChannel *)channel policy:(NSUInteger)mask{
- (NSArray<GrowingEventPersistence *> *)getEventsToBeUploadUnsafe:(GrowingEventChannel *)channel policy:(NSUInteger)mask {
if (channel.isCustomEvent) {
return [self.realtimeEventDB getEventsWithPackageNum:self.packageNum policy:mask];
} else {
Expand Down
2 changes: 1 addition & 1 deletion Services/Database/GrowingEventFMDatabase.m
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ - (void)enumerateKeysAndValuesUsingBlock:(void (^)(NSString *key, NSString *valu
NSString *value = [set stringForColumn:@"value"];
NSString *type = [set stringForColumn:@"type"];
NSUInteger policy = [set intForColumn:@"policy"];
block(key, value, type, policy,&stop);
block(key, value, type, policy, &stop);
}

[set close];
Expand Down

0 comments on commit cfd27b5

Please sign in to comment.