From d9a4d42ca0b7aefe803636d354b6f26d90b352d0 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 21 Jun 2019 10:54:53 +0800 Subject: [PATCH] Low Power: Stops background feed refresh --- iOS/AppDelegate.swift | 8 +++++++- iOS/Settings/SettingsView.swift | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index d03cae7e5..c78102625 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -253,13 +253,19 @@ private extension AppDelegate { } } - /// Performs background feed refresh. + /// Performs background feed refresh. If the device is in low power mode, it will not proceed with the refresh. /// - Parameter task: `BGAppRefreshTask` /// - Warning: As of Xcode 11 beta 2, when triggered from the debugger this doesn't work. func performBackgroundFeedRefresh(with task: BGAppRefreshTask) { scheduleBackgroundFeedRefresh() // schedule next refresh + // If the device is in low power mode, return early + if ProcessInfo.processInfo.isLowPowerModeEnabled { + os_log("Device is in low power mode. Background refresh terminated.", log: self.log, type: .info) + return + } + var startingUnreadCount = 0 DispatchQueue.global(qos: .background).async { [unowned self] in diff --git a/iOS/Settings/SettingsView.swift b/iOS/Settings/SettingsView.swift index bf7eacc1a..87e01e8be 100644 --- a/iOS/Settings/SettingsView.swift +++ b/iOS/Settings/SettingsView.swift @@ -41,7 +41,7 @@ struct SettingsView : View { } } - Section(header: Text("DATABASE")) { + Section(header: Text("DATABASE"), footer: Text("If your device is in Low Power mode feeds will not be refreshed.").lineLimit(3)) { Picker(selection: $viewModel.refreshInterval, label: Text("Refresh Interval")) { ForEach(RefreshInterval.allCases.identified(by: \.self)) { interval in Text(interval.description()).tag(interval)