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

Feature/#359 공연 등록 웹뷰 구헌 #371

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions Boolti/Boolti.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@
87A3716D2B76497B0061814E /* TicketReservationsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87A3716C2B76497B0061814E /* TicketReservationsTableViewCell.swift */; };
87A3716F2B76534B0061814E /* TicketReservationItemEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87A3716E2B76534B0061814E /* TicketReservationItemEntity.swift */; };
87B18FE72BB15A3C005A4800 /* ReversalPolicyConfirmButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87B18FE62BB15A3C005A4800 /* ReversalPolicyConfirmButton.swift */; };
87B864832CC5711800A9A836 /* WKWebViewConfiguration+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87B864822CC5711800A9A836 /* WKWebViewConfiguration+.swift */; };
87C7594C2BA93EA40009A83E /* NotificationMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87C7594B2BA93EA40009A83E /* NotificationMessage.swift */; };
87C7A5EC2CADABDA0078213E /* UnderlineSegmentedControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87C7A5EB2CADABDA0078213E /* UnderlineSegmentedControl.swift */; };
87C7A5EE2CADB1CD0078213E /* SegmentedControlContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87C7A5ED2CADB1CD0078213E /* SegmentedControlContainerView.swift */; };
Expand Down Expand Up @@ -421,6 +422,7 @@
87F7DF492B8275D30068A6C9 /* EntryCodeErrorEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87F7DF482B8275D30068A6C9 /* EntryCodeErrorEntity.swift */; };
87FB0D382B6BE7B900B42AF9 /* SwiftJWT in Frameworks */ = {isa = PBXBuildFile; productRef = 87FB0D372B6BE7B900B42AF9 /* SwiftJWT */; };
87FB0D3A2B6BE97F00B42AF9 /* IdentityTokenDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87FB0D392B6BE97F00B42AF9 /* IdentityTokenDTO.swift */; };
87FCC3C72CC4DDFD0029A0C8 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87FCC3C62CC4DDFD0029A0C8 /* WebViewController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -745,6 +747,7 @@
87A3716C2B76497B0061814E /* TicketReservationsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TicketReservationsTableViewCell.swift; sourceTree = "<group>"; };
87A3716E2B76534B0061814E /* TicketReservationItemEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TicketReservationItemEntity.swift; sourceTree = "<group>"; };
87B18FE62BB15A3C005A4800 /* ReversalPolicyConfirmButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReversalPolicyConfirmButton.swift; sourceTree = "<group>"; };
87B864822CC5711800A9A836 /* WKWebViewConfiguration+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WKWebViewConfiguration+.swift"; sourceTree = "<group>"; };
87C7594B2BA93EA40009A83E /* NotificationMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationMessage.swift; sourceTree = "<group>"; };
87C7A5EB2CADABDA0078213E /* UnderlineSegmentedControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnderlineSegmentedControl.swift; sourceTree = "<group>"; };
87C7A5ED2CADB1CD0078213E /* SegmentedControlContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentedControlContainerView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -786,6 +789,7 @@
87F7DF482B8275D30068A6C9 /* EntryCodeErrorEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryCodeErrorEntity.swift; sourceTree = "<group>"; };
87FB0D392B6BE97F00B42AF9 /* IdentityTokenDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentityTokenDTO.swift; sourceTree = "<group>"; };
87FB0D3B2B6C09B500B42AF9 /* TicketItemEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TicketItemEntity.swift; sourceTree = "<group>"; };
87FCC3C62CC4DDFD0029A0C8 /* WebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1395,6 +1399,7 @@
87F7DF442B82322E0068A6C9 /* Notification.Name+.swift */,
870C33352BBC29B600ED212C /* UICollectionReusableView+.swift */,
87EFEEDA2C7E1C4300A8993C /* Preview.swift */,
87B864822CC5711800A9A836 /* WKWebViewConfiguration+.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1800,6 +1805,7 @@
children = (
840B39532B7667B100E7F8C8 /* Cells */,
84781CCB2B5C003700D37921 /* ConcertListDIContainer.swift */,
87FCC3C62CC4DDFD0029A0C8 /* WebViewController.swift */,
84781CCD2B5C005600D37921 /* ConcertListViewController.swift */,
84781CCF2B5C006500D37921 /* ConcertViewModel.swift */,
840B39562B76688C00E7F8C8 /* ConcertCollectionViewFlowLayout.swift */,
Expand Down Expand Up @@ -2748,6 +2754,7 @@
224BEF0D2C4E6EFF00863970 /* OrderGiftPaymentResponseDTO.swift in Sources */,
84A0248E2B7B997A0095A56E /* QRScannerViewController.swift in Sources */,
846F5F3E2B7BBF60000F86AE /* QRRepository.swift in Sources */,
87FCC3C72CC4DDFD0029A0C8 /* WebViewController.swift in Sources */,
8757BAA62B5FDED7008503B5 /* OAuthRepository.swift in Sources */,
221393582C88996A00459A20 /* EditProfileViewController.swift in Sources */,
848CBF0A2B65481500239303 /* TicketingDetailDIContainer.swift in Sources */,
Expand Down Expand Up @@ -2828,6 +2835,7 @@
22DFC5522C79B1F000C8433D /* ProfileViewModel.swift in Sources */,
221393612C89C17300459A20 /* EditIntroductionView.swift in Sources */,
84EC6A642B6CF973009AC6BB /* BooltiToastView.swift in Sources */,
87B864832CC5711800A9A836 /* WKWebViewConfiguration+.swift in Sources */,
2213935A2C88997600459A20 /* EditProfileViewModel.swift in Sources */,
87A3716D2B76497B0061814E /* TicketReservationsTableViewCell.swift in Sources */,
84625A162B63C33D00CC9077 /* UITableViewCell+.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Boolti/Boolti/Application/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>REGISTER_CONCERT_URL</key>
<string>${REGISTER_CONCERT_URL}</string>
<key>GIFT_URL</key>
<string>${GIFT_URL}</string>
<key>UIUserInterfaceStyle</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// WKWebViewConfiguration+.swift
// Boolti
//
// Created by Miro on 10/21/24.
//

import Foundation
import WebKit

// TODO: 쿠키 넣는 법 다시 학습하기
extension WKWebViewConfiguration {

static func includeCookie(cookies: [HTTPCookie], completion: @escaping (WKWebViewConfiguration?) -> Void) {
let config = WKWebViewConfiguration()
let dataStore = WKWebsiteDataStore.nonPersistent()

DispatchQueue.main.async {
let waitGroup = DispatchGroup()

for cookie in cookies {
waitGroup.enter()
dataStore.httpCookieStore.setCookie(cookie) {
waitGroup.leave()
}
}

waitGroup.notify(queue: DispatchQueue.main) {
config.websiteDataStore = dataStore
completion(config)
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ extension ConcertListViewController: UICollectionViewDelegate {
let viewController = concertDetailViewControllerFactory(self.viewModel.output.topConcerts[indexPath.row].id)
self.navigationController?.pushViewController(viewController, animated: true)
case .banner:
guard let url = URL(string: "https://boolti.in/login") else { return }
self.openSafari(with: url)
let viewController = WebViewController()
self.navigationController?.pushViewController(viewController, animated: true)
case .bottomConcerts:
let viewController = concertDetailViewControllerFactory(self.viewModel.output.bottomConcerts[indexPath.row].id)
self.navigationController?.pushViewController(viewController, animated: true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import UIKit
import WebKit

import SnapKit
import RxSwift

// TODO: 재사용가능하게 변경하기
final class WebViewController: UIViewController {

private let disposeBag = DisposeBag()

private let navigationBar = BooltiNavigationBar(type: .backButton)

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.isHidden = true
}

override func viewDidLoad() {
super.viewDidLoad()

self.configureSubviews()
self.bindUIComponent()
}

private func bindUIComponent() {
self.navigationBar.didBackButtonTap()
.asDriver(onErrorJustReturn: ())
.drive(with: self) { owner, _ in
owner.navigationController?.popViewController(animated: true)
}
.disposed(by: self.disposeBag)
}

private func configureSubviews() {
self.view.backgroundColor = .white00
self.view.addSubview(navigationBar)

self.navigationBar.snp.makeConstraints { make in
make.top.equalToSuperview()
make.horizontalEdges.equalToSuperview()
}

self.prepareWebConfiguration { [weak self] config in
guard let self = self, let config = config else { return }

let webView = WKWebView(frame: .zero, configuration: config)
self.view.addSubview(webView)

webView.snp.makeConstraints { make in
make.top.equalTo(self.navigationBar.snp.bottom)
make.horizontalEdges.bottom.equalToSuperview()
}

guard let url = URL(string: Environment.REGISTER_CONCERT_URL) else { return }
let request = URLRequest(url: url)
webView.load(request)
}
}

private func prepareWebConfiguration(completion: @escaping (WKWebViewConfiguration?) -> Void) {
let accessToken = UserDefaults.accessToken
let refreshToken = UserDefaults.refreshToken

guard let authCookie = HTTPCookie(properties: [
.domain: ".boolti.in",
.path: "/",
.name: "x-access-token",
.value: accessToken,
.secure: "TRUE",
]) else {
return
}

guard let uuidCookie = HTTPCookie(properties: [
.domain: ".boolti.in",
.path: "/",
.name: "x-refresh-token",
.value: refreshToken,
.secure: "TRUE",
]) else {
return
}

WKWebViewConfiguration.includeCookie(cookies: [authCookie, uuidCookie]) {
completion($0)
}
}
}
10 changes: 9 additions & 1 deletion Boolti/Boolti/Support/Enviroment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum Environment: String {
enum Plist {
static let baseURL = "BASE_URL"
static let giftURL = "GIFT_URL"
static let registerConcertURL = "REGISTER_CONCERT_URL"
static let kakaoNativeAppKey = "KAKAO_NATIVE_APP_KEY"
static let tossPaymentsKey = "TOSS_PAYMENTS_KEY"
}
Expand All @@ -38,7 +39,14 @@ enum Environment: String {
}
return string
}()


static let REGISTER_CONCERT_URL: String = {
guard let string = Environment.infoDictionary[Keys.Plist.registerConcertURL] as? String else {
fatalError("Register Concert URL not set in plist for this environment")
}
return string
}()

static let KAKAO_NATIVE_APP_KEY: String = {
guard let string = Environment.infoDictionary[Keys.Plist.kakaoNativeAppKey] as? String else {
fatalError("KAKAO_NATIVE_APP_KEY not set in plist for this environment")
Expand Down