diff --git a/FCKit/Sources/FCKit/FeatureFlag/FeatureFlag.swift b/FCKit/Sources/FCKit/FeatureFlag/FeatureFlag.swift index ed98300d..1dfb2b34 100644 --- a/FCKit/Sources/FCKit/FeatureFlag/FeatureFlag.swift +++ b/FCKit/Sources/FCKit/FeatureFlag/FeatureFlag.swift @@ -13,7 +13,6 @@ public enum FeatureFlagBool: String, CaseIterable, FeatureFlag { case adsEnabled = "ads_enabled" case newResultsBannerEnabled = "new_results_banner_enabled" - case sharedBackgroundDeliveryPublishers = "shared_background_delivery_publishers" case ignoreManuallyEnteredHealthKitData = "ignore_manually_entered_health_kit_data" public var defaultValue: Data { false } diff --git a/FriendlyCompetitions/Managers/ActivitySummary/ActivitySummaryManager.swift b/FriendlyCompetitions/Managers/ActivitySummary/ActivitySummaryManager.swift index 90d331e6..d6efa9b9 100644 --- a/FriendlyCompetitions/Managers/ActivitySummary/ActivitySummaryManager.swift +++ b/FriendlyCompetitions/Managers/ActivitySummary/ActivitySummaryManager.swift @@ -86,27 +86,23 @@ final class ActivitySummaryManager: ActivitySummaryManaging { ] permissionTypes.forEach { permission in - if featureFlagManager.value(forBool: .sharedBackgroundDeliveryPublishers) { - healthKitManager.registerBackgroundDeliveryTask(for: permission) { [weak self] in - guard let self else { return .just(()) } - if let fetchAndUploadPublisher = self.fetchAndUploadPublisher { - return fetchAndUploadPublisher - } else { - let publisher = fetchAndUpload() - .first() - .handleEvents(receiveCompletion: { _ in - self.fetchAndUploadPublisher = nil - }, receiveCancel: { - self.fetchAndUploadPublisher = nil - }) - .share() - .eraseToAnyPublisher() - self.fetchAndUploadPublisher = publisher - return publisher - } + healthKitManager.registerBackgroundDeliveryTask(for: permission) { [weak self] in + guard let self else { return .just(()) } + if let fetchAndUploadPublisher = self.fetchAndUploadPublisher { + return fetchAndUploadPublisher + } else { + let publisher = fetchAndUpload() + .first() + .handleEvents(receiveCompletion: { _ in + self.fetchAndUploadPublisher = nil + }, receiveCancel: { + self.fetchAndUploadPublisher = nil + }) + .share() + .eraseToAnyPublisher() + self.fetchAndUploadPublisher = publisher + return publisher } - } else { - healthKitManager.registerBackgroundDeliveryPublisher(for: permission, publisher: fetchAndUpload()) } } } diff --git a/FriendlyCompetitions/Managers/HealthKit/HealthKitManager.swift b/FriendlyCompetitions/Managers/HealthKit/HealthKitManager.swift index b3d53222..0b06b417 100644 --- a/FriendlyCompetitions/Managers/HealthKit/HealthKitManager.swift +++ b/FriendlyCompetitions/Managers/HealthKit/HealthKitManager.swift @@ -15,7 +15,6 @@ protocol HealthKitManaging { func execute(_ query: AnyHealthKitQuery) func registerBackgroundDeliveryTask(for permission: HealthKitPermissionType, task: @escaping HealthKitBackgroundDeliveryTask) - func registerBackgroundDeliveryPublisher(for permission: HealthKitPermissionType, publisher: AnyPublisher) func registerForBackgroundDelivery() func shouldRequest(_ permissions: [HealthKitPermissionType]) -> AnyPublisher @@ -56,11 +55,6 @@ final class HealthKitManager: HealthKitManaging { backgroundDeliveryTasks[permission] = tasks.appending(task) } - func registerBackgroundDeliveryPublisher(for permission: HealthKitPermissionType, publisher: AnyPublisher) { - let publishers = backgroundDeliveryPublishers[permission] ?? [] - backgroundDeliveryPublishers[permission] = publishers.appending(publisher) - } - func shouldRequest(_ permissions: [HealthKitPermissionType]) -> AnyPublisher { healthStore .shouldRequest(permissions) @@ -118,7 +112,6 @@ final class HealthKitManager: HealthKitManaging { if error.isHealthKitAuthorizationError { backgroundDeliveryTasks[permission]?.removeAll() - backgroundDeliveryPublishers[permission]?.removeAll() healthStore.disableBackgroundDelivery(for: permission) .sink() .store(in: &cancellables) @@ -128,11 +121,7 @@ final class HealthKitManager: HealthKitManaging { case .success(let backgroundDeliveryCompletion): let publishers: [AnyPublisher] - if featureFlagManager.value(forBool: .sharedBackgroundDeliveryPublishers) { - publishers = backgroundDeliveryTasks[permission]?.map { $0() } ?? [] - } else { - publishers = backgroundDeliveryPublishers[permission] ?? [] - } + publishers = backgroundDeliveryTasks[permission]?.map { $0() } ?? [] guard publishers.isNotEmpty else { analyticsManager.log(event: .healthKitBGDelieveryMissingPublisher(permission: permission.rawValue)) diff --git a/FriendlyCompetitions/Managers/StepCount/StepCountManager.swift b/FriendlyCompetitions/Managers/StepCount/StepCountManager.swift index 461f0bdb..7d83171c 100644 --- a/FriendlyCompetitions/Managers/StepCount/StepCountManager.swift +++ b/FriendlyCompetitions/Managers/StepCount/StepCountManager.swift @@ -25,11 +25,7 @@ final class StepCountManager: StepCountManaging { // MARK: - Lifecycle init() { - if featureFlagManager.value(forBool: .sharedBackgroundDeliveryPublishers) { - healthKitManager.registerBackgroundDeliveryTask(for: .stepCount, task: fetchAndUpload) - } else { - healthKitManager.registerBackgroundDeliveryPublisher(for: .stepCount, publisher: fetchAndUpload()) - } + healthKitManager.registerBackgroundDeliveryTask(for: .stepCount, task: fetchAndUpload) fetchAndUpload() .sink() diff --git a/FriendlyCompetitions/Managers/Workout/WorkoutManager.swift b/FriendlyCompetitions/Managers/Workout/WorkoutManager.swift index af7e93c6..b5852b82 100644 --- a/FriendlyCompetitions/Managers/Workout/WorkoutManager.swift +++ b/FriendlyCompetitions/Managers/Workout/WorkoutManager.swift @@ -72,27 +72,23 @@ final class WorkoutManager: WorkoutManaging { ] permissionTypes.forEach { permission in - if featureFlagManager.value(forBool: .sharedBackgroundDeliveryPublishers) { - healthKitManager.registerBackgroundDeliveryTask(for: permission) { [weak self] in - guard let self else { return .just(()) } - if let fetchAndUploadPublisher { - return fetchAndUploadPublisher - } else { - let publisher = fetchAndUpload() - .first() - .handleEvents(receiveCompletion: { _ in - self.fetchAndUploadPublisher = nil - }, receiveCancel: { - self.fetchAndUploadPublisher = nil - }) - .share() - .eraseToAnyPublisher() - self.fetchAndUploadPublisher = publisher - return publisher - } + healthKitManager.registerBackgroundDeliveryTask(for: permission) { [weak self] in + guard let self else { return .just(()) } + if let fetchAndUploadPublisher { + return fetchAndUploadPublisher + } else { + let publisher = fetchAndUpload() + .first() + .handleEvents(receiveCompletion: { _ in + self.fetchAndUploadPublisher = nil + }, receiveCancel: { + self.fetchAndUploadPublisher = nil + }) + .share() + .eraseToAnyPublisher() + self.fetchAndUploadPublisher = publisher + return publisher } - } else { - healthKitManager.registerBackgroundDeliveryPublisher(for: permission, publisher: fetchAndUpload()) } } } diff --git a/FriendlyCompetitions/Sourcery/AutoMockable.generated.swift b/FriendlyCompetitions/Sourcery/AutoMockable.generated.swift index e0d77948..b4d33592 100644 --- a/FriendlyCompetitions/Sourcery/AutoMockable.generated.swift +++ b/FriendlyCompetitions/Sourcery/AutoMockable.generated.swift @@ -998,23 +998,6 @@ class HealthKitManagingMock: HealthKitManaging { registerBackgroundDeliveryTaskForTaskClosure?(permission, task) } - //MARK: - registerBackgroundDeliveryPublisher - - var registerBackgroundDeliveryPublisherForPublisherCallsCount = 0 - var registerBackgroundDeliveryPublisherForPublisherCalled: Bool { - return registerBackgroundDeliveryPublisherForPublisherCallsCount > 0 - } - var registerBackgroundDeliveryPublisherForPublisherReceivedArguments: (permission: HealthKitPermissionType, publisher: AnyPublisher)? - var registerBackgroundDeliveryPublisherForPublisherReceivedInvocations: [(permission: HealthKitPermissionType, publisher: AnyPublisher)] = [] - var registerBackgroundDeliveryPublisherForPublisherClosure: ((HealthKitPermissionType, AnyPublisher) -> Void)? - - func registerBackgroundDeliveryPublisher(for permission: HealthKitPermissionType, publisher: AnyPublisher) { - registerBackgroundDeliveryPublisherForPublisherCallsCount += 1 - registerBackgroundDeliveryPublisherForPublisherReceivedArguments = (permission: permission, publisher: publisher) - registerBackgroundDeliveryPublisherForPublisherReceivedInvocations.append((permission: permission, publisher: publisher)) - registerBackgroundDeliveryPublisherForPublisherClosure?(permission, publisher) - } - //MARK: - registerForBackgroundDelivery var registerForBackgroundDeliveryCallsCount = 0 diff --git a/FriendlyCompetitionsTests/Managers/ActivitySummaryManagerTests.swift b/FriendlyCompetitionsTests/Managers/ActivitySummaryManagerTests.swift index 806070de..cfc9c34f 100644 --- a/FriendlyCompetitionsTests/Managers/ActivitySummaryManagerTests.swift +++ b/FriendlyCompetitionsTests/Managers/ActivitySummaryManagerTests.swift @@ -15,13 +15,19 @@ final class ActivitySummaryManagerTests: FCTestCase { override func setUp() { super.setUp() userManager.user = .evan - featureFlagManager.valueForBoolFeatureFlagFeatureFlagBoolBoolClosure = { $0 == .sharedBackgroundDeliveryPublishers ? true : false } featureFlagManager.valueForDoubleFeatureFlagFeatureFlagDoubleDoubleClosure = { flag in switch flag { case .dataUploadGracePeriodHours: return 12.0 default: return 0.0 } } + featureFlagManager.valueForBoolFeatureFlagFeatureFlagBoolBoolClosure = { flag in + switch flag { + case .ignoreManuallyEnteredHealthKitData: return true + case .adsEnabled: return true + case .newResultsBannerEnabled: return true + } + } } func testThatItFetchesActivitySummariesAndSetsCurrentOnSuccess() { diff --git a/FriendlyCompetitionsTests/Managers/StepCountManagerTests.swift b/FriendlyCompetitionsTests/Managers/StepCountManagerTests.swift index cc1ffd61..05b0c50c 100644 --- a/FriendlyCompetitionsTests/Managers/StepCountManagerTests.swift +++ b/FriendlyCompetitionsTests/Managers/StepCountManagerTests.swift @@ -9,13 +9,19 @@ final class StepCountManagerTests: FCTestCase { override func setUp() { super.setUp() userManager.user = .evan - featureFlagManager.valueForBoolFeatureFlagFeatureFlagBoolBoolClosure = { $0 == .sharedBackgroundDeliveryPublishers ? true : false } featureFlagManager.valueForDoubleFeatureFlagFeatureFlagDoubleDoubleClosure = { flag in switch flag { case .dataUploadGracePeriodHours: return 12.0 default: return 0.0 } } + featureFlagManager.valueForBoolFeatureFlagFeatureFlagBoolBoolClosure = { flag in + switch flag { + case .ignoreManuallyEnteredHealthKitData: return true + case .adsEnabled: return true + case .newResultsBannerEnabled: return true + } + } } func testThatItRefetchesWhenCompetitionsChange() { diff --git a/FriendlyCompetitionsTests/Managers/WorkoutManagerTests.swift b/FriendlyCompetitionsTests/Managers/WorkoutManagerTests.swift index 2d1de128..670dd7ef 100644 --- a/FriendlyCompetitionsTests/Managers/WorkoutManagerTests.swift +++ b/FriendlyCompetitionsTests/Managers/WorkoutManagerTests.swift @@ -14,13 +14,19 @@ final class WorkoutManagerTests: FCTestCase { override func setUp() { super.setUp() userManager.user = .evan - featureFlagManager.valueForBoolFeatureFlagFeatureFlagBoolBoolClosure = { $0 == .sharedBackgroundDeliveryPublishers ? true : false } featureFlagManager.valueForDoubleFeatureFlagFeatureFlagDoubleDoubleClosure = { flag in switch flag { case .dataUploadGracePeriodHours: return 12.0 default: return 0.0 } } + featureFlagManager.valueForBoolFeatureFlagFeatureFlagBoolBoolClosure = { flag in + switch flag { + case .ignoreManuallyEnteredHealthKitData: return true + case .adsEnabled: return true + case .newResultsBannerEnabled: return true + } + } } func testThatItRefetchesWhenCompetitionsChange() {