Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Firebase/InAppMessaging/Analytics/FIRIAMClearcutLogStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,18 @@ - (instancetype)initWithExpireAfterInSeconds:(NSInteger)expireInSeconds
_timeFetcher = timeFetcher;
_recordExpiresInSeconds = expireInSeconds;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillBecomeInactive)
selector:@selector(appWillBecomeInactive:)
name:UIApplicationWillResignActiveNotification
object:nil];
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillBecomeInactive:)
name:UISceneWillDeactivateNotification
object:nil];
}
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000

@try {
[self loadFromCachePath:cachePath];
} @catch (NSException *exception) {
Expand All @@ -110,7 +119,7 @@ - (instancetype)initWithExpireAfterInSeconds:(NSInteger)expireInSeconds
cachePath:nil];
}

- (void)appWillBecomeInactive {
- (void)appWillBecomeInactive:(NSNotification *)notification {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), ^{
[self saveIntoCacheWithPath:nil];
});
Expand Down
13 changes: 10 additions & 3 deletions Firebase/InAppMessaging/Analytics/FIRIAMClearcutUploader.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,17 @@ - (instancetype)initWithRequestSender:(FIRIAMClearcutHttpRequestSender *)request
_strategy = strategy;
_queue = dispatch_queue_create("com.google.firebase.inappmessaging.clearcut_upload", NULL);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillEnterForeground:)
selector:@selector(scheduleNextSendFromForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];

#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(scheduleNextSendFromForeground:)
name:UISceneWillEnterForegroundNotification
object:nil];
}
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
_userDefaults = userDefaults ? userDefaults : [NSUserDefaults standardUserDefaults];
// it would be 0 if it does not exist, which is equvilent to saying that
// you can send now
Expand All @@ -121,7 +128,7 @@ - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)appWillEnterForeground:(UIApplication *)application {
- (void)scheduleNextSendFromForeground:(NSNotification *)notification {
FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM260010",
@"App foregrounded, FIRIAMClearcutUploader will seed next send");
[self scheduleNextSend];
Expand Down
13 changes: 10 additions & 3 deletions Firebase/InAppMessaging/Flows/FIRIAMActivityLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,17 @@ - (instancetype)initWithMaxCountBeforeReduce:(NSInteger)maxBeforeReduce
_isDirty = NO;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillBecomeInactive)
selector:@selector(appWillBecomeInactive:)
name:UIApplicationWillResignActiveNotification
object:nil];

#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
[[NSNotificationCenter defaultCenter] addObserver:self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there situations where appWillBecomeInactive could be called twice, i.e. could UIApplicationWillResignActiveNotification and UISceneWillDeactivateNotification both be fired for the same app close?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing for becoming active.

selector:@selector(appWillBecomeInactive:)
name:UISceneWillDeactivateNotification
object:nil];
}
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (loadFromCache) {
@try {
[self loadFromCachePath:nil];
Expand Down Expand Up @@ -162,7 +169,7 @@ - (BOOL)saveIntoCacheWithPath:(NSString *)cacheFilePath {
}
}

- (void)appWillBecomeInactive {
- (void)appWillBecomeInactive:(NSNotification *)notification {
FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM310004",
@"App will become inactive, save"
" activity logs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ @implementation FIRIAMDisplayCheckOnAppForegroundFlow
- (void)start {
FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM500002",
@"Start observing app foreground notifications for rendering messages.");
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(checkAndDisplayNextAppForegroundMessageFromForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(checkAndDisplayNextAppForegroundMessageFromForeground:)
name:UISceneWillEnterForegroundNotification
object:nil];
}
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
}

- (void)appWillEnterForeground:(UIApplication *)application {
- (void)checkAndDisplayNextAppForegroundMessageFromForeground:(NSNotification *)notification {
FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM500001",
@"App foregrounded, wake up to check in-app messaging.");

Expand Down
10 changes: 9 additions & 1 deletion Firebase/InAppMessaging/Flows/FIRIAMFetchOnAppForegroundFlow.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ - (void)start {
selector:@selector(appWillEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillEnterForeground:)
name:UISceneWillEnterForegroundNotification
object:nil];
}
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
}

- (void)appWillEnterForeground:(UIApplication *)application {
- (void)appWillEnterForeground:(NSNotification *)notification {
FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM600001",
@"App foregrounded, wake up to see if we can fetch in-app messaging.");
// for fetch operation, dispatch it to non main UI thread to avoid blocking. It's ok to dispatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ - (void)setupAutoDismissTimer {
}

// Handlers for app become active inactive so that we can better adjust our auto dismiss feature
- (void)appDidBecomeInactive:(UIApplication *)application {
[super appDidBecomeInactive:application];
- (void)appWillBecomeInactive:(NSNotification *)notification {
[super appWillBecomeInactive:notification];
[self.autoDismissTimer invalidate];
}

- (void)appDidBecomeActive:(UIApplication *)application {
[super appDidBecomeActive:application];
- (void)appDidBecomeActive:(NSNotification *)notification {
[super appDidBecomeActive:notification];
[self setupAutoDismissTimer];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ NS_ASSUME_NONNULL_BEGIN
// These are the two methods we use to respond to app state change for the purpose of
// actual display time tracking. Subclass can override this one to have more logic for responding
// to the two events, but remember to trigger super's implementation.
- (void)appDidBecomeInactive:(UIApplication *)application;
- (void)appDidBecomeActive:(UIApplication *)application;
- (void)appWillBecomeInactive:(NSNotification *)notification;
- (void)appDidBecomeActive:(NSNotification *)notification;

// Tracking the aggregate impression time for the rendered message. Used to determine when
// we are eaching the minimal iimpression time requirements. Exposed so that sub banner vc
Expand Down
20 changes: 16 additions & 4 deletions Firebase/InAppMessagingDisplay/FIDBaseRenderingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,27 @@ - (void)viewDidLoad {
// app foreground/background events since viewDidAppear/viewDidDisappear are not
// triggered when app switches happen.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appDidBecomeInactive:)
selector:@selector(appWillBecomeInactive:)
name:UIApplicationWillResignActiveNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];

#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appWillBecomeInactive:)
name:UISceneWillDeactivateNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appDidBecomeActive:)
name:UISceneDidActivateNotification
object:nil];
}
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
self.aggregateImpressionTimeInSeconds = 0;
}

Expand Down Expand Up @@ -92,11 +104,11 @@ - (void)dealloc {
[NSNotificationCenter.defaultCenter removeObserver:self];
}

- (void)appDidBecomeInactive:(UIApplication *)application {
- (void)appWillBecomeInactive:(NSNotification *)notification {
[self impressionStopCheckpoint];
}

- (void)appDidBecomeActive:(UIApplication *)application {
- (void)appDidBecomeActive:(NSNotification *)notification {
[self impressionStartCheckpoint];
}

Expand Down
45 changes: 42 additions & 3 deletions Firebase/InAppMessagingDisplay/FIDRenderingWindowHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ + (UIWindow *)UIWindowForModalView {
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
UIWindowForModal = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
UIWindowForModal = [[UIWindow alloc] initWithWindowScene:foregroundedScene];
} else {
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
UIWindowForModal = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
}
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
UIWindowForModal.windowLevel = UIWindowLevelNormal;
});
return UIWindowForModal;
Expand All @@ -35,7 +44,17 @@ + (UIWindow *)UIWindowForBannerView {
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
UIWindowForBanner = [[FIDBannerViewUIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
UIWindowForBanner = [[FIDBannerViewUIWindow alloc] initWithWindowScene:foregroundedScene];
} else {
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
UIWindowForBanner =
[[FIDBannerViewUIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
}
#endif
UIWindowForBanner.windowLevel = UIWindowLevelNormal;
});

Expand All @@ -47,10 +66,30 @@ + (UIWindow *)UIWindowForImageOnlyView {
static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{
UIWindowForImageOnly = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
if (@available(iOS 13.0, *)) {
UIWindowScene *foregroundedScene = [[self class] foregroundedScene];
UIWindowForImageOnly = [[UIWindow alloc] initWithWindowScene:foregroundedScene];
} else {
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
UIWindowForImageOnly = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
}
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
UIWindowForImageOnly.windowLevel = UIWindowLevelNormal;
});

return UIWindowForImageOnly;
}

#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
+ (UIWindowScene *)foregroundedScene API_AVAILABLE(ios(13.0)) {
for (UIWindowScene *connectedScene in [UIApplication sharedApplication].connectedScenes) {
if (connectedScene.activationState == UISceneActivationStateForegroundActive) {
return connectedScene;
}
}
return nil;
}
#endif
@end