-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
115 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// WebView.swift | ||
// Treehouse | ||
// | ||
// Created by 윤영서 on 8/1/24. | ||
// | ||
|
||
import SwiftUI | ||
import WebKit | ||
|
||
struct WebView: UIViewRepresentable { | ||
let path: String | ||
|
||
func makeUIView(context: Context) -> WKWebView { | ||
return WKWebView() | ||
} | ||
|
||
func updateUIView(_ uiView: WKWebView, context: Context) { | ||
// Keychain에서 토큰 가져오기 | ||
guard let accessToken = KeychainHelper.shared.load(for: Config.accessTokenKey) else { | ||
print("Access token not found") | ||
return | ||
} | ||
|
||
// URL 생성 | ||
guard let url = URL(string: Config.webFrontURL + path) else { | ||
print("Invalid URL") | ||
return | ||
} | ||
|
||
// URLRequest 생성 및 Authorization 헤더 설정 | ||
var request = URLRequest(url: url) | ||
request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization") | ||
|
||
// WebView에 요청 로드 | ||
uiView.load(request) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Treehouse/Treehouse/Presentation/TreeBranch/TreeBranchScene/Views/TreeBranchView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// TreeBranchView.swift | ||
// Treehouse | ||
// | ||
// Created by 윤영서 on 8/1/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct TreeBranchView: View { | ||
@Environment(ViewRouter.self) var viewRouter: ViewRouter | ||
|
||
var body: some View { | ||
if let treehouseId = viewRouter.selectedTreehouseId { | ||
WebView(path: "branchView/tree/\(treehouseId)") | ||
.edgesIgnoringSafeArea(.all) | ||
|
||
} else { | ||
Text("트리하우스 ID를 선택해주세요.") | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
TreeBranchView() | ||
.environment(ViewRouter()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters