From 7cd7343585753a22bbc64a4c3543fd7eefca052a Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Tue, 12 Oct 2021 17:05:13 +1100 Subject: [PATCH] schedule background refresh tasks --- Session/Meta/AppDelegate.m | 8 ++++++++ Session/Meta/AppDelegate.swift | 15 ++++++++++++--- .../Notifications/PushNotificationAPI.swift | 2 +- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Session/Meta/AppDelegate.m b/Session/Meta/AppDelegate.m index 0e4ccd8fd..a96e311cd 100644 --- a/Session/Meta/AppDelegate.m +++ b/Session/Meta/AppDelegate.m @@ -256,6 +256,10 @@ static NSTimeInterval launchStartedAt; [AppReadiness runNowOrWhenAppDidBecomeReady:^{ [self handleActivation]; }]; + + if (@available(iOS 13, *)) { + [self cancelAllPendingBackgroundTasks]; + } // Clear all notifications whenever we become active. // When opening the app from a notification, @@ -283,6 +287,10 @@ static NSTimeInterval launchStartedAt; [sharedUserDefaults synchronize]; [DDLog flushLog]; + + if (@available(iOS 13, *)) { + [self scheduleAppRefresh]; + } } #pragma mark - Orientation diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index c6958b7cc..18cc4787b 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -4,6 +4,7 @@ import SessionUIKit import UIKit import BackgroundTasks import SessionUtilitiesKit +import SessionMessagingKit extension AppDelegate { @@ -120,7 +121,7 @@ extension AppDelegate { } @available(iOS 13.0, *) - @objc func cancelAllPendingBGTask() { + @objc func cancelAllPendingBackgroundTasks() { BGTaskScheduler.shared.cancelAllTaskRequests() } @@ -141,8 +142,16 @@ extension AppDelegate { private func handleAppRefresh(task: BGAppRefreshTask) { // Schedule a new refresh task. scheduleAppRefresh() - - + AppReadiness.runNowOrWhenAppDidBecomeReady{ + BackgroundPoller.poll(completionHandler: { result in + if result == .failed { + task.setTaskCompleted(success: false) + + } else { + task.setTaskCompleted(success: true) + } + }) + } } } diff --git a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift index 8fccb96ec..c44649c60 100644 --- a/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift +++ b/SessionMessagingKit/Sending & Receiving/Notifications/PushNotificationAPI.swift @@ -5,7 +5,7 @@ import PromiseKit public final class PushNotificationAPI : NSObject { // MARK: Settings - public static let server = "https://live.apns.getsession.org" + public static let server = "https://dev.apns.getsession.org" public static let serverPublicKey = "642a6585919742e5a2d4dc51244964fbcd8bcab2b75612407de58b810740d049" private static let maxRetryCount: UInt = 4 private static let tokenExpirationInterval: TimeInterval = 12 * 60 * 60