diff --git a/README.md b/README.md index 1b07118d..c93d290c 100644 --- a/README.md +++ b/README.md @@ -293,7 +293,7 @@ Klaviyo supports custom badge counts when configuring your push notification in #### Autoclearing Badge Count -By default, Klaviyo SDK automatically clears all badges on app open. If you want to disable this behavior, in your app's `Info.plist`, add a new entry for `disable_Klaviyo_badge_autoclearing` as a Boolean set to `YES`. +By default, Klaviyo SDK automatically clears all badges on app open. If you want to disable this behavior, in your app's `Info.plist`, add a new entry for `klaviyo_badge_autoclearing` as a Boolean set to `NO`. You can turn this on again by setting this to `YES`. #### Handling Other Badging Sources diff --git a/Sources/KlaviyoCore/KlaviyoEnvironment.swift b/Sources/KlaviyoCore/KlaviyoEnvironment.swift index 38ab2ea2..6ff336fe 100644 --- a/Sources/KlaviyoCore/KlaviyoEnvironment.swift +++ b/Sources/KlaviyoCore/KlaviyoEnvironment.swift @@ -22,7 +22,7 @@ public struct KlaviyoEnvironment { notificationCenterPublisher: @escaping (NSNotification.Name) -> AnyPublisher, getNotificationSettings: @escaping () async -> PushEnablement, getBackgroundSetting: @escaping () -> PushBackground, - getBadgeAutoClearingIsDisabled: @escaping () async -> Bool, + getBadgeAutoClearingSetting: @escaping () async -> Bool, startReachability: @escaping () throws -> Void, stopReachability: @escaping () -> Void, reachabilityStatus: @escaping () -> Reachability.NetworkStatus?, @@ -49,7 +49,7 @@ public struct KlaviyoEnvironment { self.notificationCenterPublisher = notificationCenterPublisher self.getNotificationSettings = getNotificationSettings self.getBackgroundSetting = getBackgroundSetting - self.getBadgeAutoClearingIsDisabled = getBadgeAutoClearingIsDisabled + self.getBadgeAutoClearingSetting = getBadgeAutoClearingSetting self.startReachability = startReachability self.stopReachability = stopReachability self.reachabilityStatus = reachabilityStatus @@ -96,7 +96,7 @@ public struct KlaviyoEnvironment { public var notificationCenterPublisher: (NSNotification.Name) -> AnyPublisher public var getNotificationSettings: () async -> PushEnablement public var getBackgroundSetting: () -> PushBackground - public var getBadgeAutoClearingIsDisabled: () async -> Bool + public var getBadgeAutoClearingSetting: () async -> Bool public var startReachability: () throws -> Void public var stopReachability: () -> Void @@ -154,8 +154,8 @@ public struct KlaviyoEnvironment { getBackgroundSetting: { .create(from: UIApplication.shared.backgroundRefreshStatus) }, - getBadgeAutoClearingIsDisabled: { - Bundle.main.object(forInfoDictionaryKey: "disable_Klaviyo_badge_autoclearing") as? Bool ?? false + getBadgeAutoClearingSetting: { + Bundle.main.object(forInfoDictionaryKey: "klaviyo_badge_autoclearing") as? Bool ?? true }, startReachability: { try reachabilityService?.startNotifier() diff --git a/Sources/KlaviyoSwift/StateManagement/StateManagement.swift b/Sources/KlaviyoSwift/StateManagement/StateManagement.swift index 3f1f43ee..0b052730 100644 --- a/Sources/KlaviyoSwift/StateManagement/StateManagement.swift +++ b/Sources/KlaviyoSwift/StateManagement/StateManagement.swift @@ -304,11 +304,11 @@ struct KlaviyoReducer: ReducerProtocol { .run { send in let settings = await environment.getNotificationSettings() await send(KlaviyoAction.setPushEnablement(settings)) - let disabled = await environment.getBadgeAutoClearingIsDisabled() - if disabled { - KlaviyoBadgeCountUtil.syncBadgeCount() - } else { + let autoclearing = await environment.getBadgeAutoClearingSetting() + if autoclearing { await send(KlaviyoAction.setBadgeCount(0)) + } else { + KlaviyoBadgeCountUtil.syncBadgeCount() } }, environment.timer(state.flushInterval) diff --git a/Tests/KlaviyoCoreTests/TestUtils.swift b/Tests/KlaviyoCoreTests/TestUtils.swift index 45effce0..427bef74 100644 --- a/Tests/KlaviyoCoreTests/TestUtils.swift +++ b/Tests/KlaviyoCoreTests/TestUtils.swift @@ -87,7 +87,7 @@ extension KlaviyoEnvironment { notificationCenterPublisher: { _ in Empty().eraseToAnyPublisher() }, getNotificationSettings: { .authorized }, getBackgroundSetting: { .available }, - getBadgeAutoClearingIsDisabled: { false }, + getBadgeAutoClearingSetting: { true }, startReachability: {}, stopReachability: {}, reachabilityStatus: { nil }, diff --git a/Tests/KlaviyoSwiftTests/KlaviyoTestUtils.swift b/Tests/KlaviyoSwiftTests/KlaviyoTestUtils.swift index 2172ab28..99baadea 100644 --- a/Tests/KlaviyoSwiftTests/KlaviyoTestUtils.swift +++ b/Tests/KlaviyoSwiftTests/KlaviyoTestUtils.swift @@ -35,7 +35,7 @@ extension KlaviyoEnvironment { notificationCenterPublisher: { _ in Empty().eraseToAnyPublisher() }, getNotificationSettings: { .authorized }, getBackgroundSetting: { .available }, - getBadgeAutoClearingIsDisabled: { false }, + getBadgeAutoClearingSetting: { true }, startReachability: {}, stopReachability: {}, reachabilityStatus: { nil }, diff --git a/Tests/KlaviyoSwiftTests/StateManagementEdgeCaseTests.swift b/Tests/KlaviyoSwiftTests/StateManagementEdgeCaseTests.swift index 93da00d7..de96dc2d 100644 --- a/Tests/KlaviyoSwiftTests/StateManagementEdgeCaseTests.swift +++ b/Tests/KlaviyoSwiftTests/StateManagementEdgeCaseTests.swift @@ -347,7 +347,7 @@ class StateManagementEdgeCaseTests: XCTestCase { @MainActor func testDefaultBadgeClearingOn() async throws { let apiKey = "fake-key" - environment.getBadgeAutoClearingIsDisabled = { false } + environment.getBadgeAutoClearingSetting = { true } let expectation = XCTestExpectation(description: "Should set badge to 0") klaviyoSwiftEnvironment.setBadgeCount = { _ in expectation.fulfill() @@ -380,7 +380,7 @@ class StateManagementEdgeCaseTests: XCTestCase { @MainActor func testDefaultBadgeClearingOff() async { let apiKey = "fake-key" - environment.getBadgeAutoClearingIsDisabled = { true } + environment.getBadgeAutoClearingSetting = { false } let expectation = XCTestExpectation(description: "Should not set badge to 0") expectation.isInverted = true klaviyoSwiftEnvironment.setBadgeCount = { _ in