From 478f63c35679bbb7b5519f6c27246abe11c7d220 Mon Sep 17 00:00:00 2001 From: "Alyssa.Yu" Date: Tue, 5 Sep 2023 10:29:18 -0700 Subject: [PATCH] feat: test observe did changeSreeenNotification --- Sources/Amplitude/UIViewController+AMPScreen.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sources/Amplitude/UIViewController+AMPScreen.m b/Sources/Amplitude/UIViewController+AMPScreen.m index 397fd7c2..1568a860 100644 --- a/Sources/Amplitude/UIViewController+AMPScreen.m +++ b/Sources/Amplitude/UIViewController+AMPScreen.m @@ -37,6 +37,10 @@ #import "UIViewController+AMPScreen.h" #import "Amplitude.h" #import "AMPConstants.h" +#import + +static NSNotificationName const __UIWindowSceneDidChangeScreenNotification = @"__UIWindowSceneDidChangeScreenNotification"; + #if !TARGET_OS_OSX && !TARGET_OS_WATCH @@ -134,7 +138,10 @@ - (void)amp_viewDidAppear:(BOOL)animated { } } - NSLog(@"**********Before print view hierarchy**********"); + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(screenChanged:) + name:__UIWindowSceneDidChangeScreenNotification + object:nil]; [[Amplitude instance] logEvent:kAMPScreenViewed withEventProperties:@{ @@ -143,7 +150,12 @@ - (void)amp_viewDidAppear:(BOOL)animated { // call original method, this is not recurrsive method call [self amp_viewDidAppear:animated]; - +} + +- (void)screenChanged:(NSNotification *)notification { + // Handle the screen change here + NSLog(@"**********Before print view hierarchy**********"); + NSLog(@"Screen changed!"); printViewHierarchy(self.view, 0); }