일반웹뷰라면 밑에 링크가 맞는데
https://stackoverflow.com/questions/36139062/call-swift-function-with-javascript-using-uiwebview
WKWebView에서는 변화사항이 있는거같다.
https://stackoverflow.com/questions/40761218/javascript-call-to-swift-from-uiwebview
사용된정보
https://styleshare.github.io/2016/09/14/ios-10-url-open.html
https://samwize.com/2016/06/08/complete-guide-to-implementing-wkwebview/
https://gist.github.com/starhoshi/efde2a0283f05e6a4d32a225617294ab
결론
WKNavigationDelete추가
override func viewDidLoad() {
super.viewDidLoad()
WebView.navigationDelegate = self
}
HTML페이지에는
location.href = "custom-scheme//test"
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if let url = navigationAction.request.url, url.scheme != "http" && url.scheme != "https" {
print(url.scheme)
print(url.host)
//UIApplication.shared.openURL(url)
decisionHandler(.cancel)
} else {
decisionHandler(.allow)
}
}
PRINT결과
Optional("custom-scheme")
Optional("test")
'모바일 > IOS' 카테고리의 다른 글
응용 프로그램을 위한 유효한 ‘aps-environment’ 인타이틀먼트 문자열을 찾을 수 없습니다. (0) | 2018.04.25 |
---|---|
FCM 앱에서 메시지 수신 (0) | 2018.04.25 |
공유하기 UIActivityViewController (0) | 2018.03.02 |
무한스크롤 infinite scroll (0) | 2018.02.27 |
how to open an URL in Swift (0) | 2018.02.23 |