-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewController.swift
72 lines (63 loc) · 2.49 KB
/
ViewController.swift
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// ViewController.swift
// Anonace
//
// Created by Valentyn Podkamennyi on 2/8/19.
// Copyright © 2019 Datamart. All rights reserved.
//
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {
let APP_URL = "https://anonace.com/?utm_source=ios&utm_medium=app"
let APP_HOST = "anonace.com"
var webView: WKWebView!
override func loadView() {
webView = WKWebView(frame: .zero, configuration: WKWebViewConfiguration())
webView.uiDelegate = self
webView.navigationDelegate = self
self.view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: APP_URL)
var request = URLRequest(url: url!)
request.httpShouldHandleCookies = false
webView.load(request)
}
/** Handler for external links. */
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if let url = navigationAction.request.url {
if url.host != APP_HOST && url.scheme != "data" {
UIApplication.shared.open(url)
decisionHandler(.cancel)
return
}
}
decisionHandler(.allow)
}
/** Handler for javascript "confirm" function. */
func webView(_ webView: WKWebView,
runJavaScriptConfirmPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping (Bool) -> Void) {
let ac = UIAlertController(title: "Anonace", message: message, preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default) {
_ in completionHandler(true)
})
ac.addAction(UIAlertAction(title: "Cancel", style: .default) {
_ in completionHandler(false)
})
present(ac, animated: true)
}
// /** Handler for javascript "alert" function. */
// func webView(_ webView: WKWebView,
// runJavaScriptAlertPanelWithMessage message: String,
// initiatedByFrame frame: WKFrameInfo,
// completionHandler: @escaping () -> Void) {
// let ac = UIAlertController(title: "Anonace", message: message, preferredStyle: .alert)
// ac.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
// present(ac, animated: true)
// completionHandler()
// }
}