Skip to content

Commit 57f0901

Browse files
committed
[Feat] #484 - 접근 권한 허용 Alert 구현
1 parent 7ed744b commit 57f0901

File tree

4 files changed

+57
-25
lines changed

4 files changed

+57
-25
lines changed

SOPT-iOS/Projects/Core/Sources/Utils/makeAlert.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,20 @@ public extension UIViewController {
3434
alertViewController.addAction(okAction)
3535
self.present(alertViewController, animated: true, completion: completion)
3636
}
37+
38+
func makeAlert(
39+
title: String,
40+
message: String,
41+
actions: UIAlertAction...,
42+
completion: (() -> Void)? = nil
43+
) {
44+
makeVibrate()
45+
let alertVC = UIAlertController(
46+
title: title,
47+
message: message,
48+
preferredStyle: .alert
49+
)
50+
actions.forEach { alertVC.addAction($0) }
51+
self.present(alertVC, animated: true, completion: completion)
52+
}
3753
}

SOPT-iOS/Projects/Features/BaseFeatureDependency/Sources/WebView/Download/WKDownloadManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import UniformTypeIdentifiers
1111
import WebKit
1212

1313
public final class WKDownloadManager {
14+
1415
private var downloadHandlers: [UTType: WKDownloadExecutable]
1516
var webVC: SOPTWebViewControllable?
1617

SOPT-iOS/Projects/Features/BaseFeatureDependency/Sources/WebView/Download/WKImageDownloadHandler.swift

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ struct WKImageDownloadHandler: WKDownloadExecutable {
2323

2424
guard let webVC else { return nil }
2525

26-
guard await requestAuthorization()
27-
else {
28-
//TODO: 권한 요청
26+
guard await requestAuthorization() else {
27+
await presentGoToSettingAlert(from: webVC)
2928
return nil
3029
}
3130

@@ -41,8 +40,8 @@ struct WKImageDownloadHandler: WKDownloadExecutable {
4140
guard let fileURL = try? saveToTemporaryDirectory(pngData, suggestedFilename)
4241
else { return nil }
4342

44-
presentActivityVC(fileURL, from: webVC)
45-
43+
await presentActivityVC(fileURL, from: webVC)
44+
4645
return nil
4746
}
4847

@@ -60,29 +59,45 @@ struct WKImageDownloadHandler: WKDownloadExecutable {
6059
return temporaryURL
6160
}
6261

62+
@MainActor
6363
private func presentActivityVC(_ fileURL: URL, from webVC: SOPTWebViewControllable) {
64-
Task { @MainActor in
65-
let activityVC = UIActivityViewController(
66-
activityItems: [fileURL],
67-
applicationActivities: nil
68-
)
69-
70-
activityVC.completionWithItemsHandler = {
71-
activityType, completed, returnedItems, activityError in
72-
if activityType == .saveToCameraRoll {
73-
guard activityError == nil else {
74-
ToastUtils.showMDSToast(type: .error, text: "이미지 저장에 실패했습니다.")
75-
return
76-
}
77-
78-
if completed {
79-
ToastUtils.showMDSToast(type: .success, text: "이미지가 저장되었습니다.")
80-
}
64+
65+
let activityVC = UIActivityViewController(
66+
activityItems: [fileURL],
67+
applicationActivities: nil
68+
)
69+
70+
activityVC.completionWithItemsHandler = {
71+
activityType, completed, returnedItems, activityError in
72+
if activityType == .saveToCameraRoll {
73+
guard activityError == nil else {
74+
ToastUtils.showMDSToast(type: .error, text: "이미지 저장에 실패했습니다.")
75+
return
76+
}
77+
78+
if completed {
79+
ToastUtils.showMDSToast(type: .success, text: "이미지가 저장되었습니다.")
8180
}
8281
}
83-
// 공유 화면 표시
84-
webVC.vc.present(activityVC, animated: true, completion: nil)
8582
}
83+
// 공유 화면 표시
84+
webVC.vc.present(activityVC, animated: true, completion: nil)
85+
86+
}
87+
88+
@MainActor
89+
private func presentGoToSettingAlert(from webVC: SOPTWebViewControllable) {
90+
webVC.vc.makeAlert(
91+
title: "갤러리 접근 권한 설정",
92+
message: "이미지를 저장하시려면 갤러리 접근 권한이 필요합니다.",
93+
actions: .init(title: "나중에", style: .destructive),
94+
.init(title: "설정", style: .default, handler: { _ in
95+
guard let url = URL(string: UIApplication.openSettingsURLString),
96+
UIApplication.shared.canOpenURL(url) else { return }
97+
98+
UIApplication.shared.open(url, completionHandler: nil)
99+
})
100+
)
86101
}
87102
}
88103

SOPT-iOS/Projects/Features/MainFeature/Sources/MainScene/Coordinator/MainCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class MainCoordinator: DefaultMainCoordinator {
4747
self?.requestCoordinating?(.myPage(userType))
4848
}
4949
main.vm.onSafari = { [weak self] url in
50-
self?.router.pushSOPTWebView(url: "https://sopt-internal-dev.pages.dev/test/image")
50+
self?.router.pushSOPTWebView(url: url)
5151
}
5252
main.vm.onNeedSignIn = { [weak self] in
5353
self?.requestCoordinating?(.signIn)

0 commit comments

Comments
 (0)