Skip to content

Commit 6c959b1

Browse files
authored
Post UIApplication.willTerminateNotification before exiting the app (#31)
* Post UIApplication.willTerminateNotification before exiting the app * Fix typo
1 parent 60f508a commit 6c959b1

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Example/DemoApp/UpdateUtil.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,14 @@ struct UpdateUtil {
8383
}
8484
DispatchQueue.main.async {
8585
UIApplication.shared.open(url) { _ in
86-
exit(0)
86+
// Post notification event before closing the app
87+
NotificationCenter.default.post(name: UIApplication.willTerminateNotification, object: nil)
88+
89+
// Close the app after a slight delay so it has time to execute code for the notification
90+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
91+
// We need to exit since iOS doesn't start the install until the app exits
92+
exit(0)
93+
}
8794
}
8895
}
8996
}

Sources/ETDistribution.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,14 @@ public final class ETDistribution: NSObject {
276276
return
277277
}
278278
UIApplication.shared.open(url) { _ in
279-
// We need to exit since iOS doesn't start the install until the app exits
280-
exit(0)
279+
// Post notification event before closing the app
280+
NotificationCenter.default.post(name: UIApplication.willTerminateNotification, object: nil)
281+
282+
// Close the app after a slight delay so it has time to execute code for the notification
283+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
284+
// We need to exit since iOS doesn't start the install until the app exits
285+
exit(0)
286+
}
281287
}
282288
}
283289

0 commit comments

Comments
 (0)