schedule background refresh tasks

pull/560/head
ryanzhao 4 years ago
parent c1e5511ed4
commit 7cd7343585

@ -256,6 +256,10 @@ static NSTimeInterval launchStartedAt;
[AppReadiness runNowOrWhenAppDidBecomeReady:^{ [AppReadiness runNowOrWhenAppDidBecomeReady:^{
[self handleActivation]; [self handleActivation];
}]; }];
if (@available(iOS 13, *)) {
[self cancelAllPendingBackgroundTasks];
}
// Clear all notifications whenever we become active. // Clear all notifications whenever we become active.
// When opening the app from a notification, // When opening the app from a notification,
@ -283,6 +287,10 @@ static NSTimeInterval launchStartedAt;
[sharedUserDefaults synchronize]; [sharedUserDefaults synchronize];
[DDLog flushLog]; [DDLog flushLog];
if (@available(iOS 13, *)) {
[self scheduleAppRefresh];
}
} }
#pragma mark - Orientation #pragma mark - Orientation

@ -4,6 +4,7 @@ import SessionUIKit
import UIKit import UIKit
import BackgroundTasks import BackgroundTasks
import SessionUtilitiesKit import SessionUtilitiesKit
import SessionMessagingKit
extension AppDelegate { extension AppDelegate {
@ -120,7 +121,7 @@ extension AppDelegate {
} }
@available(iOS 13.0, *) @available(iOS 13.0, *)
@objc func cancelAllPendingBGTask() { @objc func cancelAllPendingBackgroundTasks() {
BGTaskScheduler.shared.cancelAllTaskRequests() BGTaskScheduler.shared.cancelAllTaskRequests()
} }
@ -141,8 +142,16 @@ extension AppDelegate {
private func handleAppRefresh(task: BGAppRefreshTask) { private func handleAppRefresh(task: BGAppRefreshTask) {
// Schedule a new refresh task. // Schedule a new refresh task.
scheduleAppRefresh() scheduleAppRefresh()
AppReadiness.runNowOrWhenAppDidBecomeReady{
BackgroundPoller.poll(completionHandler: { result in
if result == .failed {
task.setTaskCompleted(success: false)
} else {
task.setTaskCompleted(success: true)
}
})
}
} }
} }

@ -5,7 +5,7 @@ import PromiseKit
public final class PushNotificationAPI : NSObject { public final class PushNotificationAPI : NSObject {
// MARK: Settings // 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" public static let serverPublicKey = "642a6585919742e5a2d4dc51244964fbcd8bcab2b75612407de58b810740d049"
private static let maxRetryCount: UInt = 4 private static let maxRetryCount: UInt = 4
private static let tokenExpirationInterval: TimeInterval = 12 * 60 * 60 private static let tokenExpirationInterval: TimeInterval = 12 * 60 * 60

Loading…
Cancel
Save