forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathios_updater
More file actions
29 lines (26 loc) · 1.08 KB
/
ios_updater
File metadata and controls
29 lines (26 loc) · 1.08 KB
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
import UIKit
class UpdateManager {
let updateURL = URL(string: "https://example.com/path/to/update.json")!
func checkForUpdate(completion: @escaping (Bool, String?) -> Void) {
let task = URLSession.shared.dataTask(with: updateURL) { data, response, error in
guard let data = data, error == nil else {
completion(false, nil)
return
}
do {
if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
let currentVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
if let latestVersion = json["version"] as? String, latestVersion != currentVersion {
let releaseNotes = json["releaseNotes"] as? String
completion(true, releaseNotes)
} else {
completion(false, nil)
}
}
} catch {
completion(false, nil)
}
}
task.resume()
}
}