This commit is contained in:
ryanzhao 2021-10-14 10:30:20 +11:00
parent 45e209f831
commit a8b8207154
3 changed files with 4 additions and 73 deletions

View file

@ -224,11 +224,7 @@ static NSTimeInterval launchStartedAt;
OWSLogInfo(@"application: didFinishLaunchingWithOptions completed.");
[self setUpCallHandling];
if (@available(iOS 13.0, *)) {
[self registerBackgroundTasks];
}
return YES;
}
@ -256,10 +252,6 @@ 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,
@ -287,10 +279,6 @@ static NSTimeInterval launchStartedAt;
[sharedUserDefaults synchronize];
[DDLog flushLog];
if (@available(iOS 13, *)) {
[self scheduleAppRefresh];
}
}
#pragma mark - Orientation

View file

@ -2,9 +2,6 @@ import PromiseKit
import WebRTC
import SessionUIKit
import UIKit
import BackgroundTasks
import SessionUtilitiesKit
import SessionMessagingKit
extension AppDelegate {
@ -103,54 +100,4 @@ extension AppDelegate {
}
}
}
// MARK: Background tasks
@available(iOS 13.0, *)
@objc func registerBackgroundTasks() {
BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.loki-project.loki-messenger.refresh", using: nil) { task in
self.handleAppRefresh(task: task as! BGAppRefreshTask)
}
BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.loki-project.loki-messenger.vibrate", using: nil) { task in
Vibration.shared.startVibration()
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 60, execute: {
Vibration.shared.stopVibrationIfPossible()
task.setTaskCompleted(success: true)
})
}
}
@available(iOS 13.0, *)
@objc func cancelAllPendingBackgroundTasks() {
BGTaskScheduler.shared.cancelAllTaskRequests()
}
@available(iOS 13.0, *)
@objc func scheduleAppRefresh() {
let request = BGAppRefreshTaskRequest(identifier: "com.loki-project.loki-messenger.refresh")
// Fetch no earlier than 15 minutes from now.
request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60)
do {
try BGTaskScheduler.shared.submit(request)
} catch {
print("Could not schedule app refresh: \(error)")
}
}
@available(iOS 13.0, *)
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)
}
})
}
}
}

View file

@ -2,11 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.loki-project.loki-messenger.vibrate</string>
<string>com.loki-project.loki-messenger.refresh</string>
</array>
<key>BuildDetails</key>
<dict>
<key>CarthageVersion</key>
@ -96,6 +91,8 @@
<string>Signal uses your contacts to find users you know. We do not store your contacts on the server.</string>
<key>NSFaceIDUsageDescription</key>
<string>Session&apos;s Screen Lock feature uses Face ID.</string>
<key>NSHumanReadableCopyright</key>
<string>com.loki-project.loki-messenger</string>
<key>NSMicrophoneUsageDescription</key>
<string>Session needs access to your microphone to record media.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
@ -123,9 +120,10 @@
</array>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>fetch</string>
<string>processing</string>
<string>remote-notification</string>
<string>voip</string>
</array>
<key>UILaunchStoryboardName</key>
<string>Launch Screen</string>
@ -141,7 +139,5 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>com.loki-project.loki-messenger</string>
</dict>
</plist>