//
//  BackgroundTask.swift
//  OrderScheduling
//
//  Created by 中道 on 2023/8/30.
//

import Foundation
import UIKit

public let BGTASK = BackgroundTask.default

open class BackgroundTask {
    public static let `default` = BackgroundTask()

    public var bgTask : UIBackgroundTaskIdentifier?
    
    func beginTask() {
        bgTask = UIApplication.shared.beginBackgroundTask()
    }
    
    func endTask() {
        if let bgTask {
            UIApplication.shared.endBackgroundTask(bgTask)
        }
        bgTask = UIBackgroundTaskIdentifier.invalid
    }
}
