Skip to content

Commit eb48492

Browse files
Nightsd01jkasten2
authored andcommitted
Add Application State Check
• Adds a check to make sure the delegate is only called if the app is in focus (and not just in the background)
1 parent 3d35032 commit eb48492

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,9 @@ + (void)setLastnonActiveMessageId:(NSString*)value { _lastnonActiveMessageId = v
17611761
+ (OSNotificationDisplayType)displayTypeForNotificationPayload:(NSDictionary *)payload {
17621762
var type = self.inFocusDisplayType;
17631763

1764-
if (![OneSignalHelper isOneSignalPayload:payload])
1764+
// check to make sure the app is in focus and it's a OneSignal notification
1765+
if (![OneSignalHelper isOneSignalPayload:payload]
1766+
|| UIApplication.sharedApplication.applicationState != UIApplicationStateActive)
17651767
return type;
17661768

17671769
let osPayload = [OSNotificationPayload parseWithApns:payload];

iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,8 @@ - (void)testOverrideNotificationDisplayType {
23022302

23032303
[OneSignal setInFocusDisplayType:OSNotificationDisplayTypeNone];
23042304

2305+
UIApplicationOverrider.currentUIApplicationState = UIApplicationStateActive;
2306+
23052307
[UnitTestCommonMethods resumeApp];
23062308
[UnitTestCommonMethods runBackgroundThreads];
23072309

0 commit comments

Comments
 (0)