Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upload notification 개선 #232

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Comment on lines +74 to +82
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

}

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])
}

}