1 // Copyright 2023-present 650 Industries. All rights reserved.
2 
3 import ExpoModulesCore
4 
5 public final class FileSystemBackgroundSessionHandler: ExpoAppDelegateSubscriber, EXSessionHandlerProtocol {
6   public typealias BackgroundSessionCompletionHandler = () -> Void
7 
8   private var completionHandlers: [String: BackgroundSessionCompletionHandler] = [:]
9 
invokeCompletionHandlernull10   public func invokeCompletionHandler(forSessionIdentifier identifier: String) {
11     guard let completionHandler = completionHandlers[identifier] else {
12       return
13     }
14     DispatchQueue.main.async {
15       completionHandler()
16     }
17     completionHandlers.removeValue(forKey: identifier)
18   }
19 
20   // MARK: - ExpoAppDelegateSubscriber
21 
22   public func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
23     completionHandlers[identifier] = completionHandler
24   }
25 }
26