From 35677bc7c46dfe2649f53622e805b4133dd602d3 Mon Sep 17 00:00:00 2001 From: Nan Date: Thu, 22 Aug 2024 16:26:33 -0700 Subject: [PATCH] wip --- .../OneSignalCoreMocks/OneSignalCoreMocks.swift | 10 ++++++++++ .../OneSignalNotifications/OSNotificationsManager.m | 5 +++-- .../OneSignalNotificationsTests.swift | 3 ++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift b/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift index 20272b36e..9c6fbd33f 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift @@ -51,24 +51,34 @@ public class OneSignalCoreMocks: NSObject { } @objc public static func backgroundApp() { + print("❌ calling OneSignalCoreMocks.backgroundApp") if OSBundleUtils.isAppUsingUIScene() { + print("❌ isAppUsingUIScene: true") if #available(iOS 13.0, *) { + print("❌ inside #available(iOS 13.0, *)") NotificationCenter.default.post(name: UIScene.willDeactivateNotification, object: nil) NotificationCenter.default.post(name: UIScene.didEnterBackgroundNotification, object: nil) } + print("❌ after #available(iOS 13.0, *)") } else { + print("❌ isAppUsingUIScene: false") NotificationCenter.default.post(name: UIApplication.willResignActiveNotification, object: nil) NotificationCenter.default.post(name: UIApplication.didEnterBackgroundNotification, object: nil) } } @objc public static func foregroundApp() { + print("❌ calling OneSignalCoreMocks.foregroundApp") if OSBundleUtils.isAppUsingUIScene() { + print("❌ isAppUsingUIScene: true") if #available(iOS 13.0, *) { + print("❌ inside #available(iOS 13.0, *)") NotificationCenter.default.post(name: UIScene.willEnterForegroundNotification, object: nil) NotificationCenter.default.post(name: UIScene.didActivateNotification, object: nil) } + print("❌ after #available(iOS 13.0, *)") } else { + print("❌ isAppUsingUIScene: false") NotificationCenter.default.post(name: UIApplication.willEnterForegroundNotification, object: nil) NotificationCenter.default.post(name: UIApplication.didBecomeActiveNotification, object: nil) } diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m index 9ce51e29b..a2dfa1032 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m +++ b/iOS_SDK/OneSignalSDK/OneSignalNotifications/OSNotificationsManager.m @@ -268,17 +268,18 @@ + (void)registerLifecycleObserver { + (void)registerLifecycleObserverAsUIScene { if (@available(iOS 13.0, *)) { - [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSNotificationManager registering for Scene Lifecycle notifications"]; + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"❌ OSNotificationManager registering for Scene Lifecycle notifications"]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground) name:@"UISceneWillEnterForegroundNotification" object:nil]; } } + (void)registerLifecycleObserverAsUIApplication { - [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"OSNotificationManager registering for Application Lifecycle notifications"]; + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"❌ OSNotificationManager registering for Application Lifecycle notifications"]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil]; } + (void)willEnterForeground { + [OneSignalLog onesignalLog:ONE_S_LL_VERBOSE message:@"❌ OSNotificationManager willEnterForeground triggered"]; [OSNotificationsManager clearBadgeCount:false fromClearAll:false]; [OSNotificationsManager sendNotificationTypesUpdateToDelegate]; } diff --git a/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift b/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift index 5052d6bf7..fabfddcbf 100644 --- a/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift +++ b/iOS_SDK/OneSignalSDK/OneSignalNotificationsTests/OneSignalNotificationsTests.swift @@ -53,7 +53,8 @@ final class OneSignalNotificationsTests: XCTestCase { XCTAssertEqual(UIApplication.shared.applicationIconBadgeNumber, 0) } - func testDontclearBadgesWhenAppBecomesActive() throws { + func testDontclearBadgesWhenAppBecomesActive() throws { // FAILS ⚠️ + print("❌ UIDevice.current.systemVersion \(UIDevice.current.systemVersion)") // NotificationManager Start to register lifecycle listener OSNotificationsManager.start() // Set badge count > 0