Skip to content

Commit ec15fa8

Browse files
authored
Merge pull request #714 from OneSignal/fix/scene_delegate_lifecycle_handlers
Fixing lifecycle methods for Scene based Applications
2 parents 792c661 + 87da90e commit ec15fa8

16 files changed

+420
-78
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp.xcodeproj/project.pbxproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@
453453
"$(PROJECT_DIR)",
454454
);
455455
INFOPLIST_FILE = OneSignalDevApp/Info.plist;
456-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
456+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
457457
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
458458
OTHER_LDFLAGS = "-ObjC";
459459
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
@@ -474,7 +474,7 @@
474474
"$(PROJECT_DIR)",
475475
);
476476
INFOPLIST_FILE = OneSignalDevApp/Info.plist;
477-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
477+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
478478
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
479479
OTHER_LDFLAGS = "-ObjC";
480480
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
@@ -494,6 +494,7 @@
494494
"$(PROJECT_DIR)",
495495
);
496496
INFOPLIST_FILE = OneSignalNotificationServiceExtension/Info.plist;
497+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
497498
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
498499
OTHER_LDFLAGS = "-ObjC";
499500
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionA;
@@ -515,6 +516,7 @@
515516
);
516517
GCC_OPTIMIZATION_LEVEL = 0;
517518
INFOPLIST_FILE = OneSignalNotificationServiceExtension/Info.plist;
519+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
518520
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
519521
OTHER_LDFLAGS = "-ObjC";
520522
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionA;

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,15 @@
421421
CAE2E5A9215D80070036FD32 /* OSNotificationPayload.m in Sources */ = {isa = PBXBuildFile; fileRef = 454F94F41FAD2E5A00D74CCF /* OSNotificationPayload.m */; };
422422
CAE2E5AA215D80380036FD32 /* OneSignalNotificationServiceExtensionHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 454F94F11FAD218000D74CCF /* OneSignalNotificationServiceExtensionHandler.m */; };
423423
CAEA1C66202BB3C600FBFE9E /* OSEmailSubscription.h in Headers */ = {isa = PBXBuildFile; fileRef = CA810FCF202BA97300A60FED /* OSEmailSubscription.h */; };
424+
DE16C14424D3724700670EFA /* OneSignalLifecycleObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = DE16C14324D3724700670EFA /* OneSignalLifecycleObserver.m */; };
425+
DE16C14524D3724700670EFA /* OneSignalLifecycleObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = DE16C14324D3724700670EFA /* OneSignalLifecycleObserver.m */; };
426+
DE16C14724D3727200670EFA /* OneSignalLifecycleObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = DE16C14624D3727200670EFA /* OneSignalLifecycleObserver.h */; };
427+
DE16C17024D3989A00670EFA /* OneSignalLifecycleObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = DE16C14324D3724700670EFA /* OneSignalLifecycleObserver.m */; };
428+
DE20425E24E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */; };
429+
DE20425F24E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */; };
430+
DE20426024E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */ = {isa = PBXBuildFile; fileRef = DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */; };
431+
DE5EFECA24D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = DE5EFEC924D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m */; };
432+
DEE8198D24E21DF000868CBA /* UIApplication+OneSignal.h in Headers */ = {isa = PBXBuildFile; fileRef = DE20425C24E21C1500350E4F /* UIApplication+OneSignal.h */; };
424433
/* End PBXBuildFile section */
425434

426435
/* Begin PBXCopyFilesBuildPhase section */
@@ -693,6 +702,12 @@
693702
CACBAAA7218A6280000ACAA5 /* OSJSONHandling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSJSONHandling.h; sourceTree = "<group>"; };
694703
CACBAAA9218A65AE000ACAA5 /* InAppMessagingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InAppMessagingTests.m; sourceTree = "<group>"; };
695704
CACBAAAB218A662B000ACAA5 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
705+
DE16C14324D3724700670EFA /* OneSignalLifecycleObserver.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalLifecycleObserver.m; sourceTree = "<group>"; };
706+
DE16C14624D3727200670EFA /* OneSignalLifecycleObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalLifecycleObserver.h; sourceTree = "<group>"; };
707+
DE20425C24E21C1500350E4F /* UIApplication+OneSignal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIApplication+OneSignal.h"; sourceTree = "<group>"; };
708+
DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIApplication+OneSignal.m"; sourceTree = "<group>"; };
709+
DE5EFEC924D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSInAppMessageViewControllerOverrider.m; sourceTree = "<group>"; };
710+
DE5EFECB24D8DC0E0032632D /* OSInAppMessageViewControllerOverrider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSInAppMessageViewControllerOverrider.h; sourceTree = "<group>"; };
696711
/* End PBXFileReference section */
697712

698713
/* Begin PBXFrameworksBuildPhase section */
@@ -831,6 +846,8 @@
831846
CAAE0DFC2195216900A57402 /* OneSignalOverrider.m */,
832847
9D348538233D2DCF00EB81C9 /* OneSignalLocationOverrider.h */,
833848
9D348539233D2E3600EB81C9 /* OneSignalLocationOverrider.m */,
849+
DE5EFECB24D8DC0E0032632D /* OSInAppMessageViewControllerOverrider.h */,
850+
DE5EFEC924D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m */,
834851
);
835852
path = Shadows;
836853
sourceTree = "<group>";
@@ -1027,6 +1044,8 @@
10271044
91C7725D1E7CCE1000D612D0 /* OneSignalInternal.h */,
10281045
912411F01E73342200E41FD7 /* OneSignal.h */,
10291046
912411F11E73342200E41FD7 /* OneSignal.m */,
1047+
DE16C14624D3727200670EFA /* OneSignalLifecycleObserver.h */,
1048+
DE16C14324D3724700670EFA /* OneSignalLifecycleObserver.m */,
10301049
CAB4112720852E48005A70D1 /* DelayedInitializationParameters.h */,
10311050
CAB4112820852E48005A70D1 /* DelayedInitializationParameters.m */,
10321051
CA70E3332023D51000019273 /* OneSignalSetEmailParameters.h */,
@@ -1091,6 +1110,8 @@
10911110
CA1A6E6820DC2E31001C41B9 /* OneSignalDialogController.m */,
10921111
CA1A6E6D20DC2E73001C41B9 /* OneSignalDialogRequest.h */,
10931112
CA1A6E6E20DC2E73001C41B9 /* OneSignalDialogRequest.m */,
1113+
DE20425C24E21C1500350E4F /* UIApplication+OneSignal.h */,
1114+
DE20425D24E21C2C00350E4F /* UIApplication+OneSignal.m */,
10941115
);
10951116
name = Categories;
10961117
sourceTree = "<group>";
@@ -1267,6 +1288,7 @@
12671288
91F58D7A1E7C7D3F0017D24D /* OneSignalNotificationSettings.h in Headers */,
12681289
CA4742E4218B8FF30020DC8C /* OSTriggerController.h in Headers */,
12691290
7A1232AA235E17B4002B6CE3 /* OSSessionManager.h in Headers */,
1291+
DE16C14724D3727200670EFA /* OneSignalLifecycleObserver.h in Headers */,
12701292
9D1BD9642379F42700A064F7 /* OSInfluenceDataDefines.h in Headers */,
12711293
7A674F192360D813001F9ACD /* OSBaseFocusTimeProcessor.h in Headers */,
12721294
CA8E19052193C76D009DA223 /* OSInAppMessagingHelpers.h in Headers */,
@@ -1306,6 +1328,7 @@
13061328
9124123D1E73342200E41FD7 /* UIApplicationDelegate+OneSignal.h in Headers */,
13071329
7AF9865324451F3900C36EAE /* OSFocusCallParams.h in Headers */,
13081330
CAB269D921B0B6F000F8A43C /* OSInAppMessageAction.h in Headers */,
1331+
DEE8198D24E21DF000868CBA /* UIApplication+OneSignal.h in Headers */,
13091332
7AECE59C23675F5700537907 /* OSFocusTimeProcessorFactory.h in Headers */,
13101333
7AECE59A23674ADC00537907 /* OSUnattributedFocusTimeProcessor.h in Headers */,
13111334
CA63AFC22022670A00E340FB /* ReattemptRequest.h in Headers */,
@@ -1541,6 +1564,7 @@
15411564
912412121E73342200E41FD7 /* OneSignalAlertViewDelegate.m in Sources */,
15421565
CA36A42D208FDEFB003EFA9A /* NSURL+OneSignal.m in Sources */,
15431566
912412421E73342200E41FD7 /* UNUserNotificationCenter+OneSignal.m in Sources */,
1567+
DE16C14424D3724700670EFA /* OneSignalLifecycleObserver.m in Sources */,
15441568
7A880F2B23FB45FB0081F5E8 /* OSInAppMessageOutcome.m in Sources */,
15451569
9124123A1E73342200E41FD7 /* OneSignalWebView.m in Sources */,
15461570
9D3300F523145AF3000F0A83 /* OneSignalViewHelper.m in Sources */,
@@ -1573,6 +1597,7 @@
15731597
CA63AFC32022670A00E340FB /* ReattemptRequest.m in Sources */,
15741598
912412221E73342200E41FD7 /* OneSignalLocation.m in Sources */,
15751599
CACBAAA4218A6243000ACAA5 /* OSInAppMessageViewController.m in Sources */,
1600+
DE20425E24E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */,
15761601
CA7FC8A021927229002C4FD9 /* OSDynamicTriggerController.m in Sources */,
15771602
7AECE59623674AB700537907 /* OSUnattributedFocusTimeProcessor.m in Sources */,
15781603
1AF75EAE1E8567FD0097B315 /* NSString+OneSignal.m in Sources */,
@@ -1630,6 +1655,7 @@
16301655
0338566B1FBBD2270002F7C1 /* OSNotificationPayload.m in Sources */,
16311656
9DDFEEF323189C0E00EAE0BB /* OneSignalViewHelper.m in Sources */,
16321657
7A880F2C23FB45FB0081F5E8 /* OSInAppMessageOutcome.m in Sources */,
1658+
DE16C14524D3724700670EFA /* OneSignalLifecycleObserver.m in Sources */,
16331659
912412431E73342200E41FD7 /* UNUserNotificationCenter+OneSignal.m in Sources */,
16341660
CA47439F2190FEA80020DC8C /* OSTrigger.m in Sources */,
16351661
9124123B1E73342200E41FD7 /* OneSignalWebView.m in Sources */,
@@ -1662,6 +1688,7 @@
16621688
CA7FC8A121927229002C4FD9 /* OSDynamicTriggerController.m in Sources */,
16631689
912412231E73342200E41FD7 /* OneSignalLocation.m in Sources */,
16641690
9D1BD965237A08A400A064F7 /* OneSignalUserDefaults.m in Sources */,
1691+
DE20425F24E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */,
16651692
7AF9863C2444C43900C36EAE /* OSInAppMessageTracker.m in Sources */,
16661693
1AF75EB01E8569720097B315 /* NSString+OneSignal.m in Sources */,
16671694
9129C6BF1E89E7AB009CB6A0 /* OSSubscription.m in Sources */,
@@ -1722,6 +1749,7 @@
17221749
CAABF34D205B157B0042F8E5 /* OneSignalExtensionBadgeHandler.m in Sources */,
17231750
912412301E73342200E41FD7 /* OneSignalSelectorHelpers.m in Sources */,
17241751
91F58D851E7C88230017D24D /* OneSignalNotificationSettingsIOS10.m in Sources */,
1752+
DE16C17024D3989A00670EFA /* OneSignalLifecycleObserver.m in Sources */,
17251753
CAAE0DFD2195216900A57402 /* OneSignalOverrider.m in Sources */,
17261754
912412241E73342200E41FD7 /* OneSignalLocation.m in Sources */,
17271755
CA8E190B2194FE0B009DA223 /* OSMessagingControllerOverrider.m in Sources */,
@@ -1745,6 +1773,7 @@
17451773
912412341E73342200E41FD7 /* OneSignalTracker.m in Sources */,
17461774
7AF98694244A567B00C36EAE /* OSOutcomeEventsCache.m in Sources */,
17471775
03866CBD2378A33B0009C1D8 /* OutcomeIntegrationTests.m in Sources */,
1776+
DE20426024E21C2C00350E4F /* UIApplication+OneSignal.m in Sources */,
17481777
CA36F35B21C33A2500300C77 /* OSInAppMessageController.m in Sources */,
17491778
9124122C1E73342200E41FD7 /* OneSignalReachability.m in Sources */,
17501779
03389F691FB548A0006537F0 /* OneSignalTrackFirebaseAnalyticsOverrider.m in Sources */,
@@ -1796,6 +1825,7 @@
17961825
7AFE856D2368DDB80091D6A5 /* OSFocusCallParams.m in Sources */,
17971826
CA8E19082193C76D009DA223 /* OSInAppMessagingHelpers.m in Sources */,
17981827
4529DEE11FA82AB300CEAB1D /* NSBundleOverrider.m in Sources */,
1828+
DE5EFECA24D8DBF70032632D /* OSInAppMessageViewControllerOverrider.m in Sources */,
17991829
7AF986602447C13C00C36EAE /* OSInfluenceDataRepository.m in Sources */,
18001830
912412441E73342200E41FD7 /* UNUserNotificationCenter+OneSignal.m in Sources */,
18011831
03866CC12378A67B0009C1D8 /* RestClientAsserts.m in Sources */,

iOS_SDK/OneSignalSDK/Source/OSMessagingController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ - (void)presentInAppMessage:(OSInAppMessage *)message {
224224
if (self.isInAppMessageShowing)
225225
return;
226226
// Return early if the app is not active
227-
if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) {
227+
if (![UIApplication applicationIsActive]) {
228228
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"Pause IAMs display due to app inactivity"];
229229
_isAppInactive = YES;
230230
return;

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
#import "OSInAppMessageAction.h"
8282
#import "OSInAppMessage.h"
8383

84+
#import "OneSignalLifecycleObserver.h"
85+
8486
#pragma clang diagnostic push
8587
#pragma clang diagnostic ignored "-Wundeclared-selector"
8688

@@ -623,6 +625,8 @@ + (id)initWithLaunchOptions:(NSDictionary*)launchOptions
623625
if ([OneSignalTrackFirebaseAnalytics libraryExists])
624626
[OneSignalTrackFirebaseAnalytics init];
625627

628+
[OneSignalLifecycleObserver registerLifecycleObserver];
629+
626630
return self;
627631
}
628632

iOS_SDK/OneSignalSDK/Source/OneSignalHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#import "OneSignal.h"
2929
#import "OneSignalWebView.h"
30+
#import "UIApplication+OneSignal.h"
3031

3132
#pragma clang diagnostic push
3233
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
*/
27+
@interface OneSignalLifecycleObserver: NSObject
28+
+ (OneSignalLifecycleObserver*) sharedInstance;
29+
+ (void)registerLifecycleObserver;
30+
+ (void)removeObserver;
31+
@end
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
*/
27+
28+
#import <Foundation/Foundation.h>
29+
#import "OneSignalLifecycleObserver.h"
30+
#import "OneSignal.h"
31+
#import "OneSignalCommonDefines.h"
32+
#import "OneSignalTracker.h"
33+
#import "OneSignalLocation.h"
34+
#import "OSMessagingController.h"
35+
#import "UIApplication+OneSignal.h"
36+
37+
@implementation OneSignalLifecycleObserver
38+
39+
static OneSignalLifecycleObserver* _instance = nil;
40+
41+
+(OneSignalLifecycleObserver*) sharedInstance {
42+
@synchronized( _instance ) {
43+
if( !_instance ) {
44+
_instance = [[OneSignalLifecycleObserver alloc] init];
45+
}
46+
}
47+
48+
return _instance;
49+
}
50+
51+
+ (void)registerLifecycleObserver {
52+
// Replacing swizzled lifecycle selectors with notification center observers for scene based Apps
53+
if ([UIApplication isAppUsingUIScene]) {
54+
[self registerLifecycleObserverAsUIScene];
55+
} else {
56+
[self registerLifecycleObserverAsUIApplication];
57+
}
58+
}
59+
60+
+ (void)registerLifecycleObserverAsUIScene {
61+
if (@available(iOS 13.0, *)) {
62+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"registering for Scene Lifecycle notifications"];
63+
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(didEnterBackground) name:UISceneDidEnterBackgroundNotification object:nil];
64+
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(didBecomeActive) name:UISceneDidActivateNotification object:nil];
65+
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(willResignActive) name:UISceneWillDeactivateNotification object:nil];
66+
}
67+
}
68+
69+
+ (void)registerLifecycleObserverAsUIApplication {
70+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"registering for Application Lifecycle notifications"];
71+
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(didEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
72+
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(didBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
73+
[[NSNotificationCenter defaultCenter] addObserver:[OneSignalLifecycleObserver sharedInstance] selector:@selector(willResignActive) name:UIApplicationWillResignActiveNotification object:nil];
74+
}
75+
76+
+ (void)removeObserver {
77+
[[NSNotificationCenter defaultCenter] removeObserver:[OneSignalLifecycleObserver sharedInstance]];
78+
}
79+
80+
- (void)didBecomeActive {
81+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"application/scene didBecomeActive"];
82+
83+
if ([OneSignal app_id]) {
84+
[OneSignalTracker onFocus:NO];
85+
[OneSignalLocation onFocus:YES];
86+
[[OSMessagingController sharedInstance] onApplicationDidBecomeActive];
87+
}
88+
}
89+
90+
- (void)willResignActive {
91+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"application/scene willResignActive"];
92+
93+
if ([OneSignal app_id])
94+
[OneSignalTracker onFocus:YES];
95+
}
96+
97+
- (void)didEnterBackground {
98+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"application/scene didEnterBackground"];
99+
100+
if ([OneSignal app_id])
101+
[OneSignalLocation onFocus:NO];
102+
}
103+
104+
- (void)dealloc {
105+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"lifecycle observer deallocated"];
106+
[[NSNotificationCenter defaultCenter] removeObserver:self];
107+
}
108+
109+
@end

iOS_SDK/OneSignalSDK/Source/OneSignalNotificationServiceExtensionHandler.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ @implementation OneSignalNotificationServiceExtensionHandler
4040

4141
+ (UNMutableNotificationContent*)didReceiveNotificationExtensionRequest:(UNNotificationRequest*)request
4242
withMutableNotificationContent:(UNMutableNotificationContent*)replacementContent {
43-
// Set default log level of NSE to VERBOSE so we get all logs from NSE logic
44-
[OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
45-
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"NSE request received, setting OneSignal log level to VERBOSE!"];
43+
44+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"NSE request received"];
4645

4746
if (!replacementContent)
4847
replacementContent = [request.content mutableCopy];

0 commit comments

Comments
 (0)