1- //
2- // OneSignalLifecycleObserver.m
3- // OneSignal
4- //
5- // Created by Elliot Mawby on 7/30/20.
6- // Copyright © 2020 Hiptic. All rights reserved.
7- //
1+ /* *
2+ Modified MIT License
3+
4+ Copyright 2020 OneSignal
5+
6+ Permission is hereby granted, free of charge, to any person obtaining a copy
7+ of this software and associated documentation files (the "Software"), to deal
8+ in the Software without restriction, including without limitation the rights
9+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ copies of the Software, and to permit persons to whom the Software is
11+ furnished to do so, subject to the following conditions:
12+
13+ 1. The above copyright notice and this permission notice shall be included in
14+ all copies or substantial portions of the Software.
15+
16+ 2. All copies of substantial portions of the Software may only be used in connection
17+ with services provided by OneSignal.
18+
19+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+ THE SOFTWARE.
26+ */
827
928#import < Foundation/Foundation.h>
1029#import " OneSignalLifecycleObserver.h"
@@ -28,18 +47,32 @@ +(OneSignalLifecycleObserver*) sharedInstance {
2847 return _instance;
2948}
3049
50+ + (BOOL )isAppUsingUIScene {
51+ if (@available (iOS 13.0 , *)) {
52+ return [[NSBundle mainBundle ] objectForInfoDictionaryKey: @" UIApplicationSceneManifest" ] != nil ;
53+ }
54+ return NO ;
55+ }
56+
3157+ (void )registerLifecycleObserver {
3258 // Replacing swizzled lifecycle selectors with notification center observers for scene based Apps
59+ if ([self isAppUsingUIScene ]) {
60+ [self registerLifecycleObserverAsUIScene ];
61+ } else {
62+ [self registerLifecycleObserverAsUIApplication ];
63+ }
64+ }
65+
66+ + (void )registerLifecycleObserverAsUIScene {
3367 if (@available (iOS 13.0 , *)) {
34- NSDictionary *sceneManifest = [[NSBundle mainBundle ] objectForInfoDictionaryKey: @" UIApplicationSceneManifest" ];
3568 [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: @" registering for Scene Lifecycle notifications" ];
36- if (sceneManifest) {
37- [[NSNotificationCenter defaultCenter ] addObserver: [OneSignalLifecycleObserver sharedInstance ] selector: @selector (didEnterBackground ) name: UISceneDidEnterBackgroundNotification object: nil ];
38- [[NSNotificationCenter defaultCenter ] addObserver: [OneSignalLifecycleObserver sharedInstance ] selector: @selector (didBecomeActive ) name: UISceneDidActivateNotification object: nil ];
39- [[NSNotificationCenter defaultCenter ] addObserver: [OneSignalLifecycleObserver sharedInstance ] selector: @selector (willResignActive ) name: UISceneWillDeactivateNotification object: nil ];
40- return ;
41- }
69+ [[NSNotificationCenter defaultCenter ] addObserver: [OneSignalLifecycleObserver sharedInstance ] selector: @selector (didEnterBackground ) name: UISceneDidEnterBackgroundNotification object: nil ];
70+ [[NSNotificationCenter defaultCenter ] addObserver: [OneSignalLifecycleObserver sharedInstance ] selector: @selector (didBecomeActive ) name: UISceneDidActivateNotification object: nil ];
71+ [[NSNotificationCenter defaultCenter ] addObserver: [OneSignalLifecycleObserver sharedInstance ] selector: @selector (willResignActive ) name: UISceneWillDeactivateNotification object: nil ];
4272 }
73+ }
74+
75+ + (void )registerLifecycleObserverAsUIApplication {
4376 [OneSignal onesignal_Log: ONE_S_LL_VERBOSE message: @" registering for Application Lifecycle notifications" ];
4477 [[NSNotificationCenter defaultCenter ] addObserver: [OneSignalLifecycleObserver sharedInstance ] selector: @selector (didEnterBackground ) name: UIApplicationDidEnterBackgroundNotification object: nil ];
4578 [[NSNotificationCenter defaultCenter ] addObserver: [OneSignalLifecycleObserver sharedInstance ] selector: @selector (didBecomeActive ) name: UIApplicationDidBecomeActiveNotification object: nil ];
0 commit comments