Good day,
I have found an interesting behaviour that I can not understand.
I have an app that has a WKWebView. I use locally saved html files to present in the webview. To present each view I have a button for each html file. In the simulator I can go between the views as I tap each button. But in the actual device, I can see both views once and then it is stuck on the second view and will not change back to the first view.
I have moved this issue into a new project where I can play with it with out messing with the rest of the app. I am getting the same issue in the test project.
@IBOutlet weak var wec: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
wec.uiDelegate = self
// Do any additional setup after loading the view.
}
@IBAction func one() {
show_web(str: "one")
}
@IBAction func two() {
show_web(str: "two")
}
func show_web(str: String) {
var dir_name: String!
switch str {
case "one":
dir_name = "one"
case "two":
dir_name = "two"
default:
return
}
let documentDirectory = create_directory_if_needed(directory: dir_name)
let index_html_url = documentDirectory!.appendingPathComponent("index.html")
print("--------------- LOADING WEB VIEW ------------------/n",
index_html_url.path,
"--------------- LOADING WEB VIEW END ------------------/n")
let request = URLRequest(url: index_html_url)
print("???????", request)
self.wec.load(request)
}
func create_directory_if_needed(directory: String) -> URL? {
let fm = FileManager.default
let documentDirectory = fm.urls(for: .documentDirectory, in: .userDomainMask)[0]
let new_folder = documentDirectory.appendingPathComponent(directory)
if !fm.fileExists(atPath: new_folder.path) {
do {
try fm.createDirectory(at: new_folder, withIntermediateDirectories: true, attributes: nil)
}catch {
print("*********** ERROR create directory ***************")
print(error)
print("*********** ERROR End ***************")
return nil
}
}
return new_folder
}
When I print the request it always shows the correct path that I want to be presented but it does not load the correct path.
--------------- LOADING WEB VIEW ------------------/n /Users/jonasrafnsson/Library/Developer/CoreSimulator/Devices/189C901B-CD20-4636-B176-0DCE7AED456D/data/Containers/Data/Application/CB8A2C28-3406-4162-9A6E-6C0B924F6874/Documents/two/index.html --------------- LOADING WEB VIEW END ------------------/n
??????? file:///Users/jonasrafnsson/Library/Developer/CoreSimulator/Devices/189C901B-CD20-4636-B176-0DCE7AED456D/data/Containers/Data/Application/CB8A2C28-3406-4162-9A6E-6C0B924F6874/Documents/two/index.html
--------------- LOADING WEB VIEW ------------------/n /Users/jonasrafnsson/Library/Developer/CoreSimulator/Devices/189C901B-CD20-4636-B176-0DCE7AED456D/data/Containers/Data/Application/CB8A2C28-3406-4162-9A6E-6C0B924F6874/Documents/one/index.html --------------- LOADING WEB VIEW END ------------------/n
??????? file:///Users/jonasrafnsson/Library/Developer/CoreSimulator/Devices/189C901B-CD20-4636-B176-0DCE7AED456D/data/Containers/Data/Application/CB8A2C28-3406-4162-9A6E-6C0B924F6874/Documents/one/index.html
Anyone seen this behaviour before?
Regards, Jonas