From 0bbdb508db8af3d3f8e1d722436238d43ebf4827 Mon Sep 17 00:00:00 2001 From: Cody Garvin Date: Tue, 9 Jun 2020 10:25:29 -0700 Subject: [PATCH] Added application object back to notifications --- .../Integrations/SEGIntegrationsManager.m | 5 ++++- Analytics/Classes/SEGAnalytics.m | 17 ++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Analytics/Classes/Integrations/SEGIntegrationsManager.m b/Analytics/Classes/Integrations/SEGIntegrationsManager.m index 1634ed17d..9e98992e2 100644 --- a/Analytics/Classes/Integrations/SEGIntegrationsManager.m +++ b/Analytics/Classes/Integrations/SEGIntegrationsManager.m @@ -116,7 +116,10 @@ - (instancetype _Nonnull)initWithAnalytics:(SEGAnalytics *_Nonnull)analytics NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; // Update settings on foreground - [nc addObserver:self selector:@selector(onAppForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; + id application = configuration.application; + if (application) { + [nc addObserver:self selector:@selector(onAppForeground:) name:UIApplicationWillEnterForegroundNotification object:application]; + } } return self; } diff --git a/Analytics/Classes/SEGAnalytics.m b/Analytics/Classes/SEGAnalytics.m index a85f6b831..e6221b21f 100644 --- a/Analytics/Classes/SEGAnalytics.m +++ b/Analytics/Classes/SEGAnalytics.m @@ -59,13 +59,16 @@ - (instancetype)initWithConfiguration:(SEGAnalyticsConfiguration *)configuration NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; // Pass through for application state change events - for (NSString *name in @[ UIApplicationDidEnterBackgroundNotification, - UIApplicationDidFinishLaunchingNotification, - UIApplicationWillEnterForegroundNotification, - UIApplicationWillTerminateNotification, - UIApplicationWillResignActiveNotification, - UIApplicationDidBecomeActiveNotification ]) { - [nc addObserver:self selector:@selector(handleAppStateNotification:) name:name object:nil]; + id application = configuration.application; + if (application) { + for (NSString *name in @[ UIApplicationDidEnterBackgroundNotification, + UIApplicationDidFinishLaunchingNotification, + UIApplicationWillEnterForegroundNotification, + UIApplicationWillTerminateNotification, + UIApplicationWillResignActiveNotification, + UIApplicationDidBecomeActiveNotification ]) { + [nc addObserver:self selector:@selector(handleAppStateNotification:) name:name object:application]; + } } if (configuration.recordScreenViews) {