Skip to content

Commit

Permalink
fix: fixed application installed and updated getting triggered in-cor…
Browse files Browse the repository at this point in the history
…rectly (#345)

Co-authored-by: Desu Sai Venkat <[email protected]>
Co-authored-by: Abhishek Pandey <[email protected]>
  • Loading branch information
3 people authored Jul 31, 2023
1 parent 307e730 commit cbdf123
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
55 changes: 30 additions & 25 deletions Sources/Classes/RSApplicationLifeCycleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,40 @@ - (void) handleAppStateNotification: (NSNotification*) notification {
}
#endif

- (void)saveCurrentBuildNumberAndVersion:(NSString *)currentBuildNumber currentVersion:(NSString *)currentVersion {
[preferenceManager saveVersionNumber:currentVersion];
[preferenceManager saveBuildNumber:currentBuildNumber];
}

- (void) applicationDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

NSString *previousVersion = [preferenceManager getVersionNumber];
NSString* previousBuildNumber = [preferenceManager getBuildNumber];

NSString *currentVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
NSString *currentBuildNumber = [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];

if (!self->config.trackLifecycleEvents) {
[self saveCurrentBuildNumberAndVersion:currentBuildNumber currentVersion:currentVersion];
return;
}
NSString *previousVersion = [preferenceManager getVersionNumber];
NSString *currentVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];

NSString* previousBuildNumber = [preferenceManager getBuildNumber];
NSString *currentBuildNumber = [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];

if (!previousVersion) {
[RSLogger logVerbose:@"RSApplicationLifeCycleManager: applicationDidFinishLaunchingWithOptions: Tracking Application Installed"];
[[RSClient sharedInstance] track:@"Application Installed" properties:@{
@"version": currentVersion,
@"build": currentBuildNumber
}];
[preferenceManager saveVersionNumber:currentVersion];
[preferenceManager saveBuildNumber:currentBuildNumber];
} else if ([RSUtils isApplicationUpdated]) {
[RSLogger logVerbose:@"RSApplicationLifeCycleManager: applicationDidFinishLaunchingWithOptions: Tracking Application Updated"];
[[RSClient sharedInstance] track:@"Application Updated" properties:@{
@"previous_version" : previousVersion ?: @"",
@"version": currentVersion,
@"previous_build": previousBuildNumber ?: @"",
@"build": currentBuildNumber
}];
[preferenceManager saveVersionNumber:currentVersion];
[preferenceManager saveBuildNumber:currentBuildNumber];
}

if (!previousVersion) {
[RSLogger logVerbose:@"RSApplicationLifeCycleManager: applicationDidFinishLaunchingWithOptions: Tracking Application Installed"];
[[RSClient sharedInstance] track:@"Application Installed" properties:@{
@"version": currentVersion,
@"build": currentBuildNumber
}];
} else if ([RSUtils isApplicationUpdated]) {
[RSLogger logVerbose:@"RSApplicationLifeCycleManager: applicationDidFinishLaunchingWithOptions: Tracking Application Updated"];
[[RSClient sharedInstance] track:@"Application Updated" properties:@{
@"previous_version" : previousVersion ?: @"",
@"version": currentVersion,
@"previous_build": previousBuildNumber ?: @"",
@"build": currentBuildNumber
}];
}
[self saveCurrentBuildNumberAndVersion:currentBuildNumber currentVersion:currentVersion];
[self sendApplicationOpenedOnLaunch:launchOptions withVersion:currentVersion];
}

Expand Down
6 changes: 2 additions & 4 deletions Sources/Classes/RSEventRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ - (instancetype)init:(NSString*)_writeKey config:(RSConfig*)_config client:(RSCl
[RSLogger logDebug:@"EventRepository: Initiating RSApplicationLifeCycleManager"];
self->applicationLifeCycleManager = [[RSApplicationLifeCycleManager alloc] initWithConfig:config andPreferenceManager:self->preferenceManager andBackGroundModeManager:self->backGroundModeManager andUserSession:self->userSession];

if (config.trackLifecycleEvents) {
[RSLogger logDebug:@"EventRepository: Enabling tracking of application lifecycle events"];
[self->applicationLifeCycleManager trackApplicationLifeCycle];
}
[RSLogger logDebug:@"EventRepository: Enabling tracking of application lifecycle events"];
[self->applicationLifeCycleManager trackApplicationLifeCycle];

if (config.recordScreenViews) {
[RSLogger logDebug:@"EventRepository: Enabling automatic recording of screen views"];
Expand Down

0 comments on commit cbdf123

Please sign in to comment.