diff --git a/Frameworks/Account/Account.xcodeproj/project.pbxproj b/Frameworks/Account/Account.xcodeproj/project.pbxproj index 4e8d20f58..2c57508bc 100644 --- a/Frameworks/Account/Account.xcodeproj/project.pbxproj +++ b/Frameworks/Account/Account.xcodeproj/project.pbxproj @@ -595,6 +595,7 @@ baseConfigurationReference = D511EEB6202422BB00712EC3 /* Account_target.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = ""; + DEVELOPMENT_TEAM = VGR7X4HYA5; }; name = Debug; }; @@ -603,6 +604,7 @@ baseConfigurationReference = D511EEB6202422BB00712EC3 /* Account_target.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = ""; + DEVELOPMENT_TEAM = VGR7X4HYA5; }; name = Release; }; diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 08cbcb50d..b888f3bf9 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -1963,12 +1963,12 @@ ORGANIZATIONNAME = "Ranchero Software"; TargetAttributes = { 6581C73220CED60000F4AD34 = { - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = M8L2WTLA8W; ProvisioningStyle = Manual; }; 840D617B2029031C009BC708 = { CreatedOnToolsVersion = 9.3; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = VGR7X4HYA5; ProvisioningStyle = Automatic; SystemCapabilities = { com.apple.BackgroundModes = { @@ -1978,7 +1978,7 @@ }; 849C645F1ED37A5D003D8FC0 = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = M8L2WTLA8W; ProvisioningStyle = Manual; SystemCapabilities = { com.apple.HardenedRuntime = { @@ -1988,7 +1988,7 @@ }; 849C64701ED37A5D003D8FC0 = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = 9C84TZ7Q6Z; ProvisioningStyle = Automatic; TestTargetID = 849C645F1ED37A5D003D8FC0; }; @@ -2810,6 +2810,7 @@ CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = VGR7X4HYA5; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu11; @@ -2879,6 +2880,7 @@ CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = VGR7X4HYA5; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu11; diff --git a/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire-iOS.xcscheme b/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire-iOS.xcscheme index 00b189403..282b0c78e 100644 --- a/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire-iOS.xcscheme +++ b/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire-iOS.xcscheme @@ -27,6 +27,15 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> + + + + @@ -49,17 +58,6 @@ - - - - - - - - Bool { + registerBackgroundTasks() + // Set up the split view let splitViewController = window!.rootViewController as! UISplitViewController let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController @@ -88,10 +88,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele let imagesFolderURL = tempDir.appendingPathComponent("Images") try! FileManager.default.createDirectory(at: imagesFolderURL, withIntermediateDirectories: true, attributes: nil) imageDownloader = ImageDownloader(folder: imagesFolderURL.absoluteString) - + authorAvatarDownloader = AuthorAvatarDownloader(imageDownloader: imageDownloader) feedIconDownloader = FeedIconDownloader(imageDownloader: imageDownloader) - + DispatchQueue.main.async { self.unreadCount = AccountManager.shared.unreadCount } @@ -103,75 +103,54 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele } } } - - updateBackgroundRefreshInterval() syncTimer = ArticleStatusSyncTimer() - + #if DEBUG - syncTimer!.update() + syncTimer!.update() #endif return true } - -// func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool { -// -// let versionNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String -// coder.encode(versionNumber, forKey: "VersionNumber") -// -// return true -// -// } -// -// func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool { -// if let storedVersionNumber = coder.decodeObject(forKey: "VersionNumber") as? String { -// let versionNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String -// if versionNumber == storedVersionNumber { -// return true -// } -// } -// return false -// } + + // func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool { + // + // let versionNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String + // coder.encode(versionNumber, forKey: "VersionNumber") + // + // return true + // + // } + // + // func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool { + // if let storedVersionNumber = coder.decodeObject(forKey: "VersionNumber") as? String { + // let versionNumber = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String + // if versionNumber == storedVersionNumber { + // return true + // } + // } + // return false + // } func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. } - + func applicationDidEnterBackground(_ application: UIApplication) { syncTimer?.invalidate() - let completeProcessing = { [unowned self] in - UIApplication.shared.endBackgroundTask(self.syncBackgroundUpdateTask) - self.syncBackgroundUpdateTask = UIBackgroundTaskIdentifier.invalid - } - - DispatchQueue.global(qos: .background).async { [unowned self] in - - self.syncBackgroundUpdateTask = UIApplication.shared.beginBackgroundTask { - completeProcessing() - os_log("Accounts sync processing terminated for running too long.", log: self.log, type: .info) - } - - DispatchQueue.main.async { - AccountManager.shared.syncArticleStatusAll() { - completeProcessing() - } - - } - - } + // Schedule background app refresh + scheduleBackgroundFeedRefresh() } - + func applicationWillEnterForeground(_ application: UIApplication) { AccountManager.shared.syncArticleStatusAll() syncTimer?.update() } - + func applicationDidBecomeActive(_ application: UIApplication) { - // If we haven't refreshed the database for 15 minutes, run a refresh automatically if let lastRefresh = AppDefaults.lastRefresh { if Date() > lastRefresh.addingTimeInterval(15 * 60) { @@ -180,78 +159,25 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele } else { AccountManager.shared.refreshAll(errorHandler: ErrorHandler.present) } - - } - - func applicationWillTerminate(_ application: UIApplication) { - shuttingDown = true - } - - func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { - - os_log("Woken to perform account refresh.", log: log, type: .info) - - var startingUnreadCount = 0 - - let completeProcessing = { [unowned self] in - - UIApplication.shared.endBackgroundTask(self.refreshBackgroundUpdateTask) - self.refreshBackgroundUpdateTask = UIBackgroundTaskIdentifier.invalid - - if startingUnreadCount < self.unreadCount { - self.sendReceivedArticlesUserNotification(newArticleCount: self.unreadCount - startingUnreadCount) - completionHandler(.newData) - } else { - completionHandler(.noData) - } - - } - - DispatchQueue.global(qos: .background).async { [unowned self] in - - self.refreshBackgroundUpdateTask = UIApplication.shared.beginBackgroundTask { - completeProcessing() - os_log("Accounts refresh processing terminated for running too long.", log: self.log, type: .info) - } - - while(!AccountManager.shared.isUnreadCountsInitialized) { - os_log("Waiting for unread counts to be initialized...", log: self.log, type: .debug) - sleep(1) - } - - startingUnreadCount = self.unreadCount - - DispatchQueue.main.async { - AccountManager.shared.refreshAll(errorHandler: ErrorHandler.log) - } - - os_log("Accounts requested to begin refresh.", log: self.log, type: .debug) - - sleep(1) - while(!AccountManager.shared.combinedRefreshProgress.isComplete) { - os_log("Waiting for account refresh processing to complete...", log: self.log, type: .debug) - sleep(1) - } - - completeProcessing() - os_log("Accounts completed refresh processing.", log: self.log, type: .info) - - } } - // MARK: - Split view - - func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool { - guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false } - guard let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController else { return false } - if topAsDetailController.navState?.currentArticle == nil { - // Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded. - return true - } - return false + func applicationWillTerminate(_ application: UIApplication) { + shuttingDown = true } - + + // MARK: - Split view + + func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool { + guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false } + guard let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController else { return false } + if topAsDetailController.navState?.currentArticle == nil { + // Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded. + return true + } + return false + } + // MARK: Notifications @objc func unreadCountDidChange(_ note: Notification) { @@ -261,9 +187,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele } @objc func userDefaultsDidChange(_ note: Notification) { - updateBackgroundRefreshInterval() + //updateBackgroundRefreshInterval() + scheduleBackgroundFeedRefresh() } - + @objc func accountRefreshDidFinish(_ note: Notification) { AppDefaults.lastRefresh = Date() } @@ -281,19 +208,93 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele } + +// MARK: - Background Tasks private extension AppDelegate { - func updateBackgroundRefreshInterval() { - let refreshInterval = AppDefaults.refreshInterval - if refreshInterval == .manually { - UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalNever) - } else { - UIApplication.shared.setMinimumBackgroundFetchInterval(AppDefaults.refreshInterval.inSeconds()) + /// Register all background tasks. + func registerBackgroundTasks() { + // Register background feed refresh. + BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.ranchero.NetNewsWire.FeedRefresh", using: nil) { (task) in + self.performBackgroundFeedRefresh(with: task as! BGAppRefreshTask) } } - func sendReceivedArticlesUserNotification(newArticleCount: Int) { + /// Schedules a background app refresh based on `AppDefaults.refreshInterval`. + func scheduleBackgroundFeedRefresh() { + let request = BGAppRefreshTaskRequest(identifier: "com.ranchero.NetNewsWire.FeedRefresh") + request.earliestBeginDate = Date(timeIntervalSinceNow: AppDefaults.refreshInterval.inSeconds()) + do { + try BGTaskScheduler.shared.submit(request) + } catch { + print("Could not schedule app refresh: \(error)") + } + } + + /// Performs background feed 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 + + var startingUnreadCount = 0 + + DispatchQueue.global(qos: .background).async { [unowned self] in + + os_log("Woken to perform account refresh.", log: self.log, type: .info) + + os_log("Getting unread count.", log: self.log, type: .info) + while(!AccountManager.shared.isUnreadCountsInitialized) { + os_log("Waiting for unread counts to be initialized...", log: self.log, type: .info) + sleep(1) + } + os_log(.info, log: self.log, "Got unread count: %i", self.unreadCount) + startingUnreadCount = self.unreadCount + + DispatchQueue.main.async { + AccountManager.shared.refreshAll(errorHandler: ErrorHandler.log) + } + os_log("Accounts requested to begin refresh.", log: self.log, type: .info) + + sleep(1) + while (!AccountManager.shared.combinedRefreshProgress.isComplete) { + os_log("Waiting for account refresh processing to complete...", log: self.log, type: .info) + sleep(1) + } + + if startingUnreadCount < self.unreadCount { + os_log("Updating unread count badge, posting notification.", log: self.log, type: .info) + self.sendReceivedArticlesUserNotification(newArticleCount: self.unreadCount - startingUnreadCount) + task.setTaskCompleted(success: true) + } else { + os_log("Account refresh operation completed.", log: self.log, type: .info) + task.setTaskCompleted(success: true) + } + } + + // set expiration handler + task.expirationHandler = { + os_log("Accounts refresh processing terminated for running too long.", log: self.log, type: .info) + task.setTaskCompleted(success: false) + } + } + +} +private extension AppDelegate { + + // func updateBackgroundRefreshInterval() { + // let refreshInterval = AppDefaults.refreshInterval + // if refreshInterval == .manually { + // UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalNever) + // } else { + // UIApplication.shared.setMinimumBackgroundFetchInterval(AppDefaults.refreshInterval.inSeconds()) + // } + // } + + func sendReceivedArticlesUserNotification(newArticleCount: Int) { + let content = UNMutableNotificationContent() content.title = NSLocalizedString("Article Download", comment: "New Articles") diff --git a/iOS/Resources/Info.plist b/iOS/Resources/Info.plist index 9cdabc745..9df415275 100644 --- a/iOS/Resources/Info.plist +++ b/iOS/Resources/Info.plist @@ -2,6 +2,10 @@ + BGTaskSchedulerPermittedIdentifiers + + com.ranchero.NetNewsWire.FeedRefresh + CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable diff --git a/submodules/RSParser b/submodules/RSParser index 52a23c95d..032edf89b 160000 --- a/submodules/RSParser +++ b/submodules/RSParser @@ -1 +1 @@ -Subproject commit 52a23c95d4cfd52b827c9f571a2271376ed070fd +Subproject commit 032edf89b64ccbbfb6c05887b239a4bf81329b92