Skip to content

Commit

Permalink
fix/#363 온보딩 + 마이페이지 킹피셔관련 모든오류 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
hooni0918 committed Sep 5, 2024
1 parent f6a7a1d commit dd5ead4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 54 deletions.
22 changes: 14 additions & 8 deletions KkuMulKum/Source/MyPage/ViewController/MyPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,16 @@ class MyPageViewController: BaseViewController, CustomActionSheetDelegate {
updateProfileImage(with: userInfo.profileImageURL)
}

private func updateProfileImage(with urlString: String?) {
private func updateProfileImage(with urlString: String?, localImage: UIImage? = nil) {
print("Attempting to update profile image with URL: \(urlString ?? "nil")")
if let localImage = localImage {
rootView.contentView.profileImageView.image = localImage
}

if let urlString = urlString, let url = URL(string: urlString) {
rootView.contentView.profileImageView.kf.setImage(
with: url,
placeholder: UIImage.imgProfile,
placeholder: localImage ?? UIImage.imgProfile,
options: [
.transition(.fade(0.2)),
.forceRefresh,
Expand All @@ -154,16 +158,18 @@ class MyPageViewController: BaseViewController, CustomActionSheetDelegate {
completionHandler: { result in
switch result {
case .success(let value):
print("Profile image loaded successfully. Size: \(value.image.size)")
print("Profile image loaded successfully from server. Size: \(value.image.size)")
case .failure(let error):
print("Failed to load profile image: \(error.localizedDescription)")
self.rootView.contentView.profileImageView.image = UIImage.imgProfile
print("Failed to load profile image from server: \(error.localizedDescription)")
if self.rootView.contentView.profileImageView.image == nil {
self.rootView.contentView.profileImageView.image = UIImage.imgProfile
}
}
}
)
} else {
print("Invalid URL or nil. Setting default profile image.")
rootView.contentView.profileImageView.image = UIImage.imgProfile
print("Invalid URL or nil. Using local image or default profile image.")
rootView.contentView.profileImageView.image = localImage ?? UIImage.imgProfile
}
}

Expand Down Expand Up @@ -212,7 +218,7 @@ class MyPageViewController: BaseViewController, CustomActionSheetDelegate {
if let imageDataString = imageDataString,
let imageData = Data(base64Encoded: imageDataString),
let image = UIImage(data: imageData) {
self?.rootView.contentView.profileImageView.image = image
self?.updateProfileImage(with: nil, localImage: image)
}
self?.needsUserInfoRefresh = true
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,17 @@ class ProfileSetupViewController: BaseViewController {
}

@objc private func confirmButtonTapped() {
Task {
let success = await viewModel.uploadProfileImage()
if success {
DispatchQueue.main.async {
let welcomeVC = WelcomeViewController(
viewModel: WelcomeViewModel(nickname: self.viewModel.nickname)
)
welcomeVC.modalPresentationStyle = .fullScreen
self.present(welcomeVC, animated: true, completion: nil)
}
}
if viewModel.isConfirmButtonEnabled.value {
viewModel.uploadProfileImage()
navigateToWelcomeScreen()
}
}

@objc private func skipButtonTapped() {
navigateToWelcomeScreen()
}

private func navigateToWelcomeScreen() {
let welcomeVC = WelcomeViewController(
viewModel: WelcomeViewModel(nickname: viewModel.nickname)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,28 @@ class ProfileSetupViewModel {
return imageData
}

func uploadProfileImage() async -> Bool {
print("uploadProfileImage 함수 호출됨")
guard let imageData = imageData else {
print("이미지 데이터가 없습니다.")
serverResponse.value = "이미지 데이터가 없습니다."
return false
}

if imageData.count > maxImageSizeBytes {
print("이미지 크기가 최대 허용 크기를 초과합니다.")
serverResponse.value = "이미지 크기가 너무 큽니다. 더 작은 이미지를 선택해주세요."
return false
}

print("업로드할 이미지 데이터 크기: \(imageData.count) bytes")

let fileName = "profile_image.jpg"
let mimeType = "image/jpeg"

do {
let _: EmptyModel = try await authService.performRequest(
.updateProfileImage(
image: imageData,
fileName: fileName,
mimeType: mimeType
)
)
serverResponse.value = "프로필 이미지가 성공적으로 업로드되었습니다."
print("프로필 이미지 업로드 성공")
func uploadProfileImage() {
guard let imageData = imageData else {
serverResponse.value = "이미지 데이터가 없습니다."
return
}

clearImageCache()
return true
} catch {
handleError(error as? NetworkError ?? .unknownError("알 수 없는 오류가 발생했습니다."))
return false
Task {
do {
let _: EmptyModel = try await authService.performRequest(
.updateProfileImage(
image: imageData,
fileName: "profile_image.jpg",
mimeType: "image/jpeg"
)
)
print("프로필 이미지가 성공적으로 업로드되었습니다.")
clearImageCache()
} catch {
print("프로필 이미지 업로드 실패: \(error.localizedDescription)")
}
}
}
}

private func handleError(_ error: NetworkError) {
switch error {
Expand Down

0 comments on commit dd5ead4

Please sign in to comment.