diff --git a/RadarSDK/Radar.m b/RadarSDK/Radar.m index 99d26538..402c5798 100644 --- a/RadarSDK/Radar.m +++ b/RadarSDK/Radar.m @@ -1054,7 +1054,7 @@ + (void)logBackgrounding { } + (void)logResigningActive { - [[RadarLogger sharedInstance] logWithLevel:RadarLogLevelDebug type:RadarLogTypeNone message:@"App resigning active" includeDate:YES includeBattery:YES]; + [[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeNone message:@"App resigning active" includeDate:YES includeBattery:YES append:YES]; } @@ -1324,11 +1324,9 @@ + (void)flushLogs { [[RadarAPIClient sharedInstance] syncLogs:flushableLogs completionHandler:^(RadarStatus status) { - if (onComplete) { - [RadarUtils runOnMainThread:^{ - onComplete(status); - }]; - } + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + onComplete(status); + }); }]; } diff --git a/RadarSDK/RadarLogBuffer.m b/RadarSDK/RadarLogBuffer.m index f69459a1..cb058fde 100644 --- a/RadarSDK/RadarLogBuffer.m +++ b/RadarSDK/RadarLogBuffer.m @@ -94,8 +94,18 @@ - (void)persistLogs { - (NSArray *)getLogFilesInTimeOrder { NSString *characterToStrip = @"_"; NSComparator compareTimeStamps = ^NSComparisonResult(NSString *str1, NSString *str2) { - return [@([[str1 stringByReplacingOccurrencesOfString:characterToStrip withString:@""] integerValue]) - compare:@([[str2 stringByReplacingOccurrencesOfString:characterToStrip withString:@""] integerValue])]; + NSArray *parts1 = [str1 componentsSeparatedByString:characterToStrip]; + NSArray *parts2 = [str2 componentsSeparatedByString:characterToStrip]; + + // Compare timestamps + NSComparisonResult result = [@([parts1[0] longLongValue]) compare:@([parts2[0] longLongValue])]; + + // If timestamps are equal, compare file counters + if (result == NSOrderedSame) { + result = [@([parts1[1] intValue]) compare:@([parts2[1] intValue])]; + } + + return result; }; return [self.fileHandler sortedFilesInDirectory:self.logFileDir usingComparator:compareTimeStamps]; diff --git a/RadarSDK/RadarLogger.m b/RadarSDK/RadarLogger.m index b5cab091..22329237 100644 --- a/RadarSDK/RadarLogger.m +++ b/RadarSDK/RadarLogger.m @@ -66,14 +66,16 @@ - (void)logWithLevel:(RadarLogLevel)level type:(RadarLogType)type message:(NSStr if (append) { [[RadarLogBuffer sharedInstance] write:level type:type message:message forcePersist:YES]; } else { - dispatch_async(dispatch_get_main_queue(), ^{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [Radar sendLog:level type:type message:message]; NSString *log = [NSString stringWithFormat:@"%@ | backgroundTimeRemaining = %g", message, [RadarUtils backgroundTimeRemaining]]; os_log(OS_LOG_DEFAULT, "%@", log); - [[RadarDelegateHolder sharedInstance] didLogMessage:log]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[RadarDelegateHolder sharedInstance] didLogMessage:log]; + }); }); } }