Skip to content

Commit 9fccced

Browse files
authored
Make show prompt function public (#28)
1 parent 6643aa6 commit 9fccced

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

Sources/ETDistribution.swift

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public final class ETDistribution: NSObject {
7676
}
7777
}
7878

79+
/// Obtain a URL to install an IPA
80+
/// - Parameter plistUrl: The URL to the plist containing the IPA information
81+
/// - Returns: a URL ready to install the IPA using Itunes Services
7982
public func buildUrlForInstall(_ plistUrl: String) -> URL? {
8083
guard plistUrl != "REQUIRES_LOGIN",
8184
var components = URLComponents(string: "itms-services://") else {
@@ -113,6 +116,40 @@ public final class ETDistribution: NSObject {
113116
}
114117
}
115118
}
119+
120+
/// Show prompt to install an update
121+
/// - Parameter release: A Distribution Release Object
122+
public func showReleaseInstallPrompt(for release: DistributionReleaseInfo) {
123+
guard release.id != UserDefaults.skippedRelease,
124+
(UserDefaults.postponeTimeout == nil || UserDefaults.postponeTimeout! < Date() ) else {
125+
return
126+
}
127+
print("ETDistribution: Update Available: \(release.downloadUrl)")
128+
let message = "New version \(release.version) is available"
129+
130+
var actions = [AlertAction]()
131+
actions.append(AlertAction(title: "Install",
132+
style: .default,
133+
handler: { [weak self] _ in
134+
self?.handleInstallRelease(release)
135+
}))
136+
actions.append(AlertAction(title: "Postpone updates for 1 day",
137+
style: .cancel,
138+
handler: { [weak self] _ in
139+
self?.handlePostponeRelease()
140+
}))
141+
actions.append(AlertAction(title: "Skip",
142+
style: .destructive,
143+
handler: { [weak self] _ in
144+
self?.handleSkipRelease(release)
145+
}))
146+
147+
DispatchQueue.main.async {
148+
UIViewController.showAlert(title: "Update Available",
149+
message: message,
150+
actions: actions)
151+
}
152+
}
116153

117154
// MARK: - Private
118155
private lazy var session = URLSession(configuration: URLSessionConfiguration.ephemeral)
@@ -186,7 +223,7 @@ public final class ETDistribution: NSObject {
186223
if let completion = completion {
187224
completion(mappedResult)
188225
} else if let response = try? mappedResult.get() {
189-
self?.handleResponse(response: response)
226+
self?.showReleaseInstallPrompt(for: response)
190227
}
191228
}
192229
}
@@ -216,38 +253,6 @@ public final class ETDistribution: NSObject {
216253
session.getReleaseInfo(request, completion: completion)
217254
}
218255

219-
private func handleResponse(response: DistributionReleaseInfo) {
220-
guard response.id != UserDefaults.skippedRelease,
221-
(UserDefaults.postponeTimeout == nil || UserDefaults.postponeTimeout! < Date() ) else {
222-
return
223-
}
224-
print("ETDistribution: Update Available: \(response.downloadUrl)")
225-
let message = "New version \(response.version) is available"
226-
227-
var actions = [AlertAction]()
228-
actions.append(AlertAction(title: "Install",
229-
style: .default,
230-
handler: { [weak self] _ in
231-
self?.handleInstallRelease(response)
232-
}))
233-
actions.append(AlertAction(title: "Postpone updates for 1 day",
234-
style: .cancel,
235-
handler: { [weak self] _ in
236-
self?.handlePostponeRelease()
237-
}))
238-
actions.append(AlertAction(title: "Skip",
239-
style: .destructive,
240-
handler: { [weak self] _ in
241-
self?.handleSkipRelease(response)
242-
}))
243-
244-
DispatchQueue.main.async {
245-
UIViewController.showAlert(title: "Update Available",
246-
message: message,
247-
actions: actions)
248-
}
249-
}
250-
251256
private func handleInstallRelease(_ release: DistributionReleaseInfo) {
252257
if release.loginRequiredForDownload, let loginSettings = loginSettings {
253258
Auth.getAccessToken(settings: loginSettings) { [weak self] result in

0 commit comments

Comments
 (0)