pull/560/head
ryanzhao 3 years ago
parent 45e209f831
commit a8b8207154

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

@ -2,9 +2,6 @@ import PromiseKit
import WebRTC import WebRTC
import SessionUIKit import SessionUIKit
import UIKit import UIKit
import BackgroundTasks
import SessionUtilitiesKit
import SessionMessagingKit
extension AppDelegate { 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)
}
})
}
}
} }

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

Loading…
Cancel
Save