웹뷰에서 javascript로 된 alert와 confirm을 띄우려면 코드를 추가해주어야 합니다.
alert와 confirm의 경우
각각 webview에 정의되어 있는 인스턴스 메소드들을 선언해주어야 합니다.
viewController 내부에 선언해주면 됩니다.
UIAlertController에서 preferredStyle을 커스텀 해줄수 있습니다.
.alert와 .actionSheet 두개의 형식이 있습니다.
원하는 형식을 선택해서 보여주고 싶은 형식을 보여주면 됩니다!
alert
func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
let alertController = UIAlertController(title: message, message: nil,
preferredStyle: .alert);
alertController.addAction(UIAlertAction(title: "확인", style: UIAlertActionStyle.cancel) {
_ in completionHandler()}
);
self.present(alertController, animated: true, completion: {});
}
confirm
func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping (Bool) -> Void) {
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "네", style: .default, handler: { (action) in
completionHandler(true)
}))
alertController.addAction(UIAlertAction(title: "아니오", style: .default, handler: { (action) in
completionHandler(false)
}))
present(alertController, animated: true) {}
}
https://developer.apple.com/documentation/webkit/wkuidelegate/1537406-webview
Apple Developer Documentation
developer.apple.com
'네이티브 > Ios' 카테고리의 다른 글
Ios webview에서 javascript를 통해 ios 기능 호출하기 ℡ (1) | 2022.04.20 |
---|---|
Ios splash image 띄우기 (Renewal) (2) | 2022.03.01 |
Ios 웹뷰 쿠키 native에서 세팅 (0) | 2022.01.22 |
Ios 웹뷰 디버깅 (0) | 2022.01.19 |
Ios Apple Native Login (0) | 2021.12.05 |