티스토리 뷰

// runJavaScriptAlertPanelWithMessage
func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
     let alertController = UIAlertController(title: nil, message: message, preferredStyle: .actionSheet)
       alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
           completionHandler()
       }))

       present(alertController, animated: true, completion: nil)
  }
  
  // runJavaScriptTextInputPanelWithPrompt
  func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (String?) -> Void) {
    
    let alertController = UIAlertController(title: nil, message: prompt, preferredStyle: .actionSheet)

    alertController.addTextField { (textField) in
        textField.text = defaultText
    }

    alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
        if let text = alertController.textFields?.first?.text {
            completionHandler(text)
        } else {
            completionHandler(defaultText)
        }
    }))

    alertController.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { (action) in
        completionHandler(nil)
    }))

    present(alertController, animated: true, completion: nil)
  }
  
  // runJavaScriptConfirmPanelWithMessage
  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: "OK", style: .default, handler: { (action) in
          completionHandler(true)
      }))

      alertController.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { (action) in
          completionHandler(false)
      }))

      present(alertController, animated: true, completion: nil)
  }

 

이런 함수들을 WKWebView에서 채택하고, 구현해줘야 웹뷰가 정상적으로 작동한다. 

날린 시간 돌려줘.............

'macOS, iOS' 카테고리의 다른 글

언제 self를 붙여주는지?  (0) 2019.12.20
[swift] ARC: Auto Reference Counting  (0) 2019.12.20
struct와 class 비교하기  (0) 2019.12.19
subscript 정리  (0) 2019.12.19
Swift format 프로젝트에 적용하기  (0) 2019.12.19
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함