1 |
efrain |
1 |
/*
|
|
|
2 |
* Copyright 2017 Google
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
#import <TargetConditionals.h>
|
|
|
18 |
#if TARGET_OS_IOS || TARGET_OS_TV
|
|
|
19 |
|
|
|
20 |
#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
|
|
|
21 |
|
|
|
22 |
#import "FirebaseInAppMessaging/Sources/FIRCore+InAppMessaging.h"
|
|
|
23 |
#import "FirebaseInAppMessaging/Sources/Private/Flows/FIRIAMFetchOnAppForegroundFlow.h"
|
|
|
24 |
@implementation FIRIAMFetchOnAppForegroundFlow
|
|
|
25 |
- (void)start {
|
|
|
26 |
FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM600002",
|
|
|
27 |
@"Start observing app foreground notifications for message fetching.");
|
|
|
28 |
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
29 |
selector:@selector(appWillEnterForeground:)
|
|
|
30 |
name:UIApplicationWillEnterForegroundNotification
|
|
|
31 |
object:nil];
|
|
|
32 |
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
|
|
|
33 |
if (@available(iOS 13.0, tvOS 13.0, *)) {
|
|
|
34 |
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
35 |
selector:@selector(appWillEnterForeground:)
|
|
|
36 |
name:UISceneWillEnterForegroundNotification
|
|
|
37 |
object:nil];
|
|
|
38 |
}
|
|
|
39 |
#endif // defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
- (void)appWillEnterForeground:(NSNotification *)notification {
|
|
|
43 |
FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM600001",
|
|
|
44 |
@"App foregrounded, wake up to see if we can fetch in-app messaging.");
|
|
|
45 |
// for fetch operation, dispatch it to non main UI thread to avoid blocking. It's ok to dispatch
|
|
|
46 |
// to a concurrent global queue instead of serial queue since app open event won't happen at
|
|
|
47 |
// fast speed to cause race conditions
|
|
|
48 |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), ^{
|
|
|
49 |
[self checkAndFetchForInitialAppLaunch:NO];
|
|
|
50 |
});
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
- (void)stop {
|
|
|
54 |
FIRLogDebug(kFIRLoggerInAppMessaging, @"I-IAM600003",
|
|
|
55 |
@"Stop observing app foreground notifications.");
|
|
|
56 |
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
- (void)dealloc {
|
|
|
60 |
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
61 |
}
|
|
|
62 |
@end
|
|
|
63 |
|
|
|
64 |
#endif // TARGET_OS_IOS || TARGET_OS_TV
|