forked from AcaMate/AcaMate_iOS
79 lines
2.3 KiB
Swift
79 lines
2.3 KiB
Swift
//
|
|
// WebView.swift
|
|
// AcaMate
|
|
//
|
|
// Created by TAnine on 3/24/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
import WebKit
|
|
|
|
struct WebView: UIViewControllerRepresentable {
|
|
@Binding var isLoding: Bool
|
|
func updateUIViewController(_ uiViewController: WebViewController, context: Context) {
|
|
}
|
|
|
|
func makeUIViewController(context: Context) -> WebViewController {
|
|
return WebViewController()
|
|
}
|
|
|
|
|
|
}
|
|
|
|
class WebViewController: UIViewController, WKUIDelegate {
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
webView()
|
|
}
|
|
|
|
func webView() {
|
|
let url = URL(string: "https://sean-59.github.io/Kakao-Postcode/")!
|
|
let request = URLRequest(url: url)
|
|
|
|
let configuration = WKWebViewConfiguration()
|
|
let contentController = WKUserContentController()
|
|
|
|
contentController.add(self, name: "callBackHandler")
|
|
configuration.userContentController = contentController
|
|
|
|
let webview = WKWebView(frame: view.bounds, configuration: configuration)
|
|
webview.uiDelegate = self
|
|
webview.navigationDelegate = self
|
|
webview.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
|
|
webview.isUserInteractionEnabled = true
|
|
webview.scrollView.isUserInteractionEnabled = true
|
|
webview.scrollView.delaysContentTouches = false
|
|
|
|
webview.load(request)
|
|
view.addSubview(webview)
|
|
|
|
}
|
|
}
|
|
|
|
extension WebViewController: WKNavigationDelegate {
|
|
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
|
|
print("웹뷰 로딩 시작")
|
|
}
|
|
|
|
|
|
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
|
print("웹뷰 로딩 완료")
|
|
// 여기서 추가 작업(예: 로딩 인디케이터 숨기기)을 수행할 수 있습니다.
|
|
}
|
|
}
|
|
|
|
extension WebViewController: WKScriptMessageHandler {
|
|
func userContentController(_ userContentController: WKUserContentController,
|
|
didReceive message: WKScriptMessage) {
|
|
if let data = message.body as? [String: Any] {
|
|
print(data)
|
|
print(data["jibunAddress"] ?? "jibunAddress 없음")
|
|
print(data["roadAddress"] ?? "roadAddress 없음")
|
|
print(data["zonecode"] ?? "zonecode 없음")
|
|
}
|
|
}
|
|
}
|
|
|