Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 31 |
Tags
- GIT
- python
- 리눅스
- ubuntu
- PER
- PyQt
- 맛집
- node.js
- MS-SQL
- 날짜
- tensorflow
- ASP
- 유니티
- 함수
- Excel
- sqlite
- 다이어트
- pandas
- 라즈베리파이
- IOS
- port
- Linux
- flutter
- PyQt5
- urllib
- Unity
- mssql
- MySQL
- javascript
- swift
Archives
아미(아름다운미소)
WKWebView 사용 시 필수 Delegate 본문
WKWebView를 사용한다면 아래의 넷은 반드시 넣어 주어야 한다. 복사->붙여 넣기 후 개발을 시작하면 됩니다.
func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping () -> Void) {
let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "확인", style: .default, handler: { (action) in
completionHandler()
}))
self.present(alertController, animated: true, completion: nil)
}
func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping (Bool) -> Void) {
let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "확인", style: .default, handler: { (action) in
completionHandler(true)
}))
alertController.addAction(UIAlertAction(title: "취소", style: .default, handler: { (action) in
completionHandler(false)
}))
self.present(alertController, animated: true, completion: nil)
}
func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping (String?) -> Void) {
let alertController = UIAlertController(title: "", message: prompt, preferredStyle: .alert)
alertController.addTextField { (textField) in
textField.text = defaultText
}
alertController.addAction(UIAlertAction(title: "확인", style: .default, handler: { (action) in
if let text = alertController.textFields?.first?.text {
completionHandler(text)
} else {
completionHandler(defaultText)
}
}))
alertController.addAction(UIAlertAction(title: "취소", style: .default, handler: { (action) in
completionHandler(nil)
}))
self.present(alertController, animated: true, completion: nil)
}
// iOS 9.0 이후 지원
//앱이 백그라운드 상태에서 포그라운드로 돌아 올때 간혹 WKWebView가 하얀 화면으로 되어 있는 경우
public func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
// 중복적으로 리로드가 일어나지 않도록 처리 필요.
webView.reload()
}
'랭귀지 > SWIFT' 카테고리의 다른 글
| Xcode - 빌드 오류 Development cannot be enabled while your device is locked (0) | 2018.03.26 |
|---|---|
| SWIFT 소스코드상에서 화면 전환 (0) | 2018.03.06 |
| iOS 키보드 타입 (0) | 2018.02.26 |
| Swift NSURLSession을 통해서 POST로 폼 내용을 전송 (0) | 2018.02.24 |
| [iOS/SWIFT] HTTP 통신하기 (0) | 2018.02.23 |
Comments