Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nan-li committed Aug 22, 2024
1 parent 039479d commit 35677bc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
10 changes: 10 additions & 0 deletions iOS_SDK/OneSignalSDK/OneSignalCoreMocks/OneSignalCoreMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35677bc

Please sign in to comment.