Skip to content

Commit

Permalink
[Feat] #90 - WebView 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
0seoYun committed Aug 8, 2024
1 parent 491343b commit 7d7c0cf
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 23 deletions.
40 changes: 40 additions & 0 deletions Treehouse/Treehouse.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@
94D388D52C2599B10058231B /* PreviewCreatedTreehouseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94D388D42C2599B10058231B /* PreviewCreatedTreehouseView.swift */; };
94D388D72C259F210058231B /* TreehouseCreatingSuccessView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94D388D62C259F210058231B /* TreehouseCreatingSuccessView.swift */; };
94D388D92C287DC00058231B /* SendInvitationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94D388D82C287DC00058231B /* SendInvitationView.swift */; };
94D5FA8A2C5BD16A000A9357 /* TreeBranchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94D5FA892C5BD16A000A9357 /* TreeBranchView.swift */; };
94D5FA8D2C5BD2BB000A9357 /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94D5FA8C2C5BD2BB000A9357 /* WebView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -551,6 +553,8 @@
94D388D42C2599B10058231B /* PreviewCreatedTreehouseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewCreatedTreehouseView.swift; sourceTree = "<group>"; };
94D388D62C259F210058231B /* TreehouseCreatingSuccessView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TreehouseCreatingSuccessView.swift; sourceTree = "<group>"; };
94D388D82C287DC00058231B /* SendInvitationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendInvitationView.swift; sourceTree = "<group>"; };
94D5FA892C5BD16A000A9357 /* TreeBranchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TreeBranchView.swift; sourceTree = "<group>"; };
94D5FA8C2C5BD2BB000A9357 /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -848,6 +852,7 @@
00CF35902BC2DF9200D9E332 /* Global */ = {
isa = PBXGroup;
children = (
94D5FA8B2C5BD29C000A9357 /* WebView */,
3F3DAE992C588CD600C1424C /* ViewModel */,
3F0AC2FD2C2D539B009F8F46 /* SwiftData */,
94D1001B2C0CC5FE00025D43 /* PhotoPicker */,
Expand Down Expand Up @@ -885,6 +890,7 @@
00CF35992BC2E2E200D9E332 /* Presentation */ = {
isa = PBXGroup;
children = (
94D5FA842C5BD0E7000A9357 /* TreeBranch */,
94D388CD2C256C5D0058231B /* CreateTreehouse */,
00C2F55E2C11C0910009C6A1 /* Profile */,
9449C6CD2BDBA7CF00FC938B /* Feed */,
Expand Down Expand Up @@ -1710,6 +1716,38 @@
path = Views;
sourceTree = "<group>";
};
94D5FA842C5BD0E7000A9357 /* TreeBranch */ = {
isa = PBXGroup;
children = (
94D5FA852C5BD118000A9357 /* TreeBranchScene */,
);
path = TreeBranch;
sourceTree = "<group>";
};
94D5FA852C5BD118000A9357 /* TreeBranchScene */ = {
isa = PBXGroup;
children = (
94D5FA862C5BD124000A9357 /* Views */,
);
path = TreeBranchScene;
sourceTree = "<group>";
};
94D5FA862C5BD124000A9357 /* Views */ = {
isa = PBXGroup;
children = (
94D5FA892C5BD16A000A9357 /* TreeBranchView.swift */,
);
path = Views;
sourceTree = "<group>";
};
94D5FA8B2C5BD29C000A9357 /* WebView */ = {
isa = PBXGroup;
children = (
94D5FA8C2C5BD2BB000A9357 /* WebView.swift */,
);
path = WebView;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -1832,6 +1870,7 @@
9412FF2F2BF6663A006A8A15 /* KeychainHelper.swift in Sources */,
944AA7122BC6E400008020C2 /* SetPhoneNumberView.swift in Sources */,
3FF4900C2C50FEAF00A6DD8A /* CreateTreehouseUseCase.swift in Sources */,
94D5FA8A2C5BD16A000A9357 /* TreeBranchView.swift in Sources */,
3FF1071B2BEA0A4600C52908 /* PostRegisterUserRequestDTO.swift in Sources */,
3F5150442C0D96BE00AD05C3 /* NetworkRequest.swift in Sources */,
3F06C30A2BFDEF3F002B771B /* PostCreateFeedPostsResponseDTO.swift in Sources */,
Expand Down Expand Up @@ -1974,6 +2013,7 @@
3F1BE13C2C214A9500D3AF1D /* AWSImageRepositoryProtocol.swift in Sources */,
3FF4901E2C510FDE00A6DD8A /* ReadMemberInfoUseCase.swift in Sources */,
3F5150462C0DD47600AD05C3 /* RegisterUserUseCase.swift in Sources */,
94D5FA8D2C5BD2BB000A9357 /* WebView.swift in Sources */,
00B591972C2355D800F7C38C /* CheckAvailableInvitationReponseEntity.swift in Sources */,
94D388D12C256DBF0058231B /* CreateTreehouseNameView.swift in Sources */,
9499D9572BF280B8007CC6CF /* NetworkServiceable.swift in Sources */,
Expand Down
38 changes: 38 additions & 0 deletions Treehouse/Treehouse/Global/WebView/WebView.swift
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ struct GetReadMemberFeedResponseDTO: Decodable {

return result
}

}

struct PostListResponseDTO: Decodable {
Expand Down
25 changes: 3 additions & 22 deletions Treehouse/Treehouse/Network/Notification/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Foundation

final class NotificationService {

private let networkServiceManager = NetworkServiceManager()

/// 알림 조회 요청 서비스
func getNotifications() async throws -> GetCheckNotificationsResponseDTO {
print("1️⃣ 🔑 GetCheckNotifications API 호출 ========================================")
Expand All @@ -18,27 +20,6 @@ final class NotificationService {
throw NetworkError.clientError(message: "Request 생성불가")
}

let (data, response) = try await URLSession.shared.data(for: urlRequest)

// 응답 데이터와 상태 코드 출력
if let httpResponse = response as? HTTPURLResponse {
print("2️⃣ Status Code: \(httpResponse.statusCode)")
print("\(httpResponse.statusCode)")
}

if let jsonString = String(data: data, encoding: .utf8) {
print("3️⃣ Response JSON")
}

// JSON 디코딩
do {
let model = try JSONDecoder().decode(BaseResponse<GetCheckNotificationsResponseDTO>.self, from: data)
print(model.data.notifications)
print("4️⃣ GetCheckNotification API 종료 ========================================")
return model.data
} catch {
print("4️⃣ GetCheckNotifiication API Error: \(String(describing: NetworkError.jsonDecodingError.errorDescription))========================================")
throw NetworkError.jsonDecodingError
}
return try await networkServiceManager.performRequest(with: urlRequest, decodingType: GetCheckNotificationsResponseDTO.self)
}
}
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())
}
7 changes: 7 additions & 0 deletions Treehouse/Treehouse/ViewRouter/ViewRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ final class ViewRouter: RouterAction {
}
}

// 추가: 선택된 트리하우스 ID
var selectedTreehouseId: Int? {
didSet {
print("Selected Treehouse ID: \(String(describing: selectedTreehouseId))")
}
}

func push(_ router: any Router) {
print("router: \(router)")
path.append(router)
Expand Down

0 comments on commit 7d7c0cf

Please sign in to comment.