//
//  PDFDownloadManager.swift
//  Sailassist
//
//  Created by Mamoru Sugita on 2023/11/13.
//

import Foundation

class PDFDownloadManager{
    static let main = PDFDownloadManager()
    
    func downloadFile(urlString: String, fileName: String) -> URL?{
        let semaphore = DispatchSemaphore(value: 0)
        guard let url = URL(string: urlString) else { return nil }
        guard let resDocPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last else { return nil }
        var filePath: URL? = resDocPath.appendingPathComponent(fileName)
        do {
            let pdfData = try Data.init(contentsOf: url)
            try pdfData.write(to: filePath!, options: .atomic)
        }catch{
            filePath = nil
        }
        return filePath
    }
}
