-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathRemoteFileManager.swift
executable file
·37 lines (27 loc) · 1.02 KB
/
RemoteFileManager.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Foundation
class RemoteFileManager {
let remoteFileURL: URL
init(remoteFileURL: URL) {
self.remoteFileURL = remoteFileURL
}
func fetchRemoteFile(_ callback: @escaping (Data) -> Void) {
performRemoteFileRequest(URLSession.shared, url: remoteFileURL, responseHandler: callback)
}
func performRemoteFileRequest(_ session: URLSession, url: URL, responseHandler: @escaping (_ data: Data) -> Void) {
let task = session.dataTask(with: url) { data, response, error in
if let error = error {
print("LaunchGate — Error: \(error.localizedDescription)")
}
guard response != nil else {
print("LaunchGate - Error because there is no response")
return
}
guard let data = data else {
print("LaunchGate — Error: Remote configuration file response was empty.")
return
}
responseHandler(data)
}
task.resume()
}
}