Skip to content

Commit

Permalink
Merge pull request #232 from boostcampwm2023/iOS/chore#230
Browse files Browse the repository at this point in the history
chore: upload notification 개선
  • Loading branch information
anyukyung authored Dec 6, 2023
2 parents dc44514 + fde03da commit f001a88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
27 changes: 12 additions & 15 deletions iOS/Layover/Layover/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,15 @@ extension SceneDelegate {
selector: #selector(routeToLoginViewController),
name: .refreshTokenDidExpired,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(showProgressView),
name: .uploadTaskStart,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(progressChanged),
name: .progressChanged,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(removeProgressView),
name: .uploadTaskDidComplete,
object: nil)
NotificationCenter.default.addObserver(forName: .uploadTaskStart, object: nil, queue: .main) { [weak self] _ in
self?.showProgressView()
}
NotificationCenter.default.addObserver(forName: .progressChanged, object: nil, queue: .main) { [weak self] notification in
self?.progressChanged(notification)
}
NotificationCenter.default.addObserver(forName: .uploadTaskDidComplete, object: nil, queue: .main) { [weak self] _ in
self?.removeProgressView()
}
}

private func removeNotificationObservers() {
Expand All @@ -107,7 +104,7 @@ extension SceneDelegate {
rootNavigationViewController.setViewControllers([LoginViewController()], animated: true)
}

@objc private func showProgressView() {
private func showProgressView() {
guard let progressViewWidth = window?.screen.bounds.width,
let windowHeight = window?.screen.bounds.height,
let tabBarViewController = window?.rootViewController as? UITabBarController else { return }
Expand All @@ -122,15 +119,15 @@ extension SceneDelegate {
}


@objc private func progressChanged(_ notification: Notification) {
private func progressChanged(_ notification: Notification) {
guard let progress = notification.userInfo?["progress"] as? Float else { return }
progressView.setProgress(progress, animated: true)
if progress == 1 {
Toast.shared.showToast(message: "업로드가 완료되었습니다 ✨")
}
}

@objc private func removeProgressView() {
private func removeProgressView() {
progressView.removeFromSuperview()
}

Expand Down
18 changes: 4 additions & 14 deletions iOS/Layover/Layover/Scenes/UploadPost/UploadPostWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,11 @@ final class UploadPostWorker: NSObject, UploadPostWorkerProtocol {
_ = try await provider.upload(fromFile: videoURL,
to: preSignedURLString,
sessionTaskDelegate: self)
await MainActor.run {
NotificationCenter.default.post(name: .uploadTaskDidComplete, object: nil)
}
NotificationCenter.default.post(name: .uploadTaskDidComplete, object: nil)
return true
} catch {
os_log(.error, log: .data, "Failed to upload Video: %@", error.localizedDescription)
await MainActor.run {
NotificationCenter.default.post(name: .uploadTaskDidComplete, object: nil)
}
NotificationCenter.default.post(name: .uploadTaskDidComplete, object: nil)
return false
}
}
Expand All @@ -76,9 +72,7 @@ final class UploadPostWorker: NSObject, UploadPostWorkerProtocol {
extension UploadPostWorker: URLSessionTaskDelegate {

func urlSession(_ session: URLSession, didCreateTask task: URLSessionTask) {
DispatchQueue.main.async {
NotificationCenter.default.post(name: .uploadTaskStart, object: nil)
}
NotificationCenter.default.post(name: .uploadTaskStart, object: nil)
}

func urlSession(
Expand All @@ -89,11 +83,7 @@ extension UploadPostWorker: URLSessionTaskDelegate {
totalBytesExpectedToSend: Int64
) {
let uploadProgress: Float = Float(Double(totalBytesSent) / Double(totalBytesExpectedToSend))
DispatchQueue.main.async {
NotificationQueue.default.enqueue(Notification(name: .progressChanged,
userInfo: ["progress": uploadProgress]),
postingStyle: .asap)
}
NotificationCenter.default.post(name: .progressChanged, object: nil, userInfo: ["progress": uploadProgress])
}

}

0 comments on commit f001a88

Please sign in to comment.