12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- //
- // ScromReaderViewModel.swift
- // LMS
- //
- // Created by Suraj Kumar Mandal on 23/09/22.
- //
- import Foundation
- import Alamofire
- class ScromReaderViewModel {
-
- var delegate: ScromReaderProtocol?
-
- func getScromData(fileId:String) {
- if let delegate = delegate {
- delegate.startLoader()
- let url = ApiURL.DownloadBase64 + "/\(fileId)"
- print(url)
- let accessToken = UserDefaults.standard.value(forKey: "accessToken") as! String
-
- let headers: HTTPHeaders = [
- "Authorization": "Bearer \(accessToken)",
- "Accept": "application/json",
- "Content-Type": "application/json"
- ]
- print(headers)
-
- AF.request(url,
- method: .get,
- encoding: URLEncoding.httpBody,
- headers: headers)
- .responseString { response in
- if response.response?.statusCode == 200 {
- switch response.result {
- case .success(_):
- delegate.stopLoader()
- let stringData = response.description.components(separatedBy: ",")
- delegate.pdfBase64(base64: stringData[1])
- break
- case .failure(let error):
- delegate.stopLoader()
- print(error.localizedDescription)
- delegate.showError(error: error.localizedDescription)
- break
- }
- } else {
- print("Server error")
- }
- }
- }
- }
- }
- protocol ScromReaderProtocol {
- func startLoader()
- func stopLoader()
- func showError(error:String)
- func pdfBase64(base64:String)
- }
|