daumPostcode / QnA

Daum 우편번호 서비스 Q&A
http://postcode.map.daum.net/guide
93 stars 13 forks source link

Unable to detect click event on selection of particular address in ios #716

Open AblyGurmeet opened 3 years ago

AblyGurmeet commented 3 years ago

Hello Team, I got stuck with an issue from last two days. Please help me.

I'm using xcode version 12.0.1 and ios version 14.0. When I click on the search its working fine My wkwebview delegates called. But I'm unable to detect the tap action on the selection of a particular address. I Search about it and found that the address list is showing using iframe and to establish a connection between iframe and main parent we need to do some changes in that file. But as we dont have access to do change in the file please let me know that how can I use this api in my iOS app using wkwebview.

Thanks in advance

Note: The code is working fine for android app. I have done all setup from my side. I'm using the below code for detect the tap action.

import UIKit import WebKit class ViewController: UIViewController, WKScriptMessageHandler, WKNavigationDelegate {

var urlPath: String = "https://"
var webview : WKWebView?

override func viewDidLoad() {
    super.viewDidLoad()

    let config = WKWebViewConfiguration()
    let controller = WKUserContentController()
    controller.add(self, name: "setAddress")
    config.userContentController = controller

    let preferences = WKPreferences()
    preferences.javaScriptCanOpenWindowsAutomatically = true
    preferences.prepareForInterfaceBuilder()
    config.preferences = preferences

    webview = WKWebView(frame: view.bounds, configuration: config)
    webview?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    webview?.uiDelegate = self
    webview?.navigationDelegate = self
    view.addSubview(webview!)
    self.loadUrl()
}

func loadUrl() {
    if let url = URL(string: urlPath) {
        let urlRequest = URLRequest(url: url)
        webview?.load(urlRequest)
        //            guard let url = Bundle.main.url(forResource: "index", withExtension: "html") else { return }
        //            let request = URLRequest(url: url)
    }
}

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
    print(message)
    print(message.body)
}

}

extension ViewController: WKUIDelegate {

func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
    configuration.dataDetectorTypes = [.all]
    let preferences = WKPreferences()
    preferences.javaScriptCanOpenWindowsAutomatically = true
    configuration.preferences = preferences
    webview = WKWebView(frame: view.bounds, configuration: configuration)
    webview!.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    webview!.navigationDelegate = self
    webview!.uiDelegate = self
    view.addSubview(webview!)
    return webview!
}
func webViewDidClose(_ webView: WKWebView) {
    webView.removeFromSuperview()
    webview = nil
}

}

daumPostcode commented 3 years ago

@AblyGurmeet Hello

Sorry. I am not an IOS developer. I can't give a guide to WKWebview.

Postcode API is Web based API, APP does not officially support and does not support "tap" events. I don't know what this "tap"

API executes "oncomplete" callback function when address is selected. Data should be received from "oncomplete" callback function and forwarded to iOS Native Code. This part should be implemented by APP developers.

Postcode API has a customizing limit. If you want more freely API, please use government API. (https://www.juso.go.kr/addrlink/main.do?cPath=99JM)

Thanks