Skip to content

Commit

Permalink
automate lifecycle logging
Browse files Browse the repository at this point in the history
  • Loading branch information
KennyHuRadar committed Jul 3, 2024
1 parent e04c526 commit 2efe6e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
18 changes: 0 additions & 18 deletions RadarSDK/Include/Radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -1096,24 +1096,6 @@ logConversionWithNotification
*/
+ (void)setLogLevel:(RadarLogLevel)level;

/**
Log application terminating. Include this in your application delegate's applicationWillTerminate: method.
*/
+ (void)logTermination;

/**
Log application entering background. Include this in your application delegate's applicationDidEnterBackground: method.
*/
+ (void)logBackgrounding;

/**
Log application resigning active. Include this in your application delegate's applicationWillResignActive: method.
*/
+ (void)logResigningActive;


#pragma mark - Helpers

/**
Expand Down
19 changes: 16 additions & 3 deletions RadarSDK/Radar.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ + (void)initializeWithPublishableKey:(NSString *)publishableKey {
selector:@selector(applicationWillEnterForeground)
name:UIApplicationWillEnterForegroundNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:[self sharedInstance]
selector:@selector(logTermination)
name:UIApplicationWillTerminateNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:[self sharedInstance]
selector:@selector(logBackgrounding)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:[self sharedInstance]
selector:@selector(logResigningActive)
name:UIApplicationWillResignActiveNotification
object:nil];

[RadarSettings setPublishableKey:publishableKey];

Expand Down Expand Up @@ -1011,16 +1024,16 @@ + (void)setLogLevel:(RadarLogLevel)level {
[RadarSettings setLogLevel:level];
}

+ (void)logTermination {
- (void)logTermination {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeNone message:@"App terminating" includeDate:YES includeBattery:YES append:YES];
}

+ (void)logBackgrounding {
- (void)logBackgrounding {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeNone message:@"App entering background" includeDate:YES includeBattery:YES append:YES];
[[RadarLogBuffer sharedInstance] persistLogs];
}

+ (void)logResigningActive {
- (void)logResigningActive {
[[RadarLogger sharedInstance] logWithLevel:RadarLogLevelInfo type:RadarLogTypeNone message:@"App resigning active" includeDate:YES includeBattery:YES];
}

Expand Down

0 comments on commit 2efe6e4

Please sign in to comment.