IOS development path (WKWebView embedded HTML5 Image Upload) 5,
The image upload function of HTML5 pages is implemented on iOS.
First, the plupload component is used on the page. There are two pitfalls in wkwebview that need to be fixed before they can be used normally.
Problem: When you click Select Photo/camera shooting on webview, the following error occurs: whose view is not in the window hierarchy. In fact, stackoverflow has an explanation of this error, but we cannot solve it in a corresponding way, because our new UIPictureView is not determined by our decision on viewDidLoad or viewWillAppear.
Solution: for example, set NavagationViewController to the Root View in three views (NavagationViewController \ mainViewController \ webViewController:
UIApplication.shared.keyWindow?.rootViewController = anotherView
Then mainViewController is set to rootviewcontroller of NavagationViewController in storyboard. Then jump to the webViewController through push:
let myStoryBoard = self.storyboard let dblzView:UITableViewController = (myStoryBoard?.instantiateViewController(withIdentifier: "dblz"))! as! UITableViewController self.navigationController?.pushViewController(dblzView, animated: true)
The error occurs because the initial View Controller opened by the app I designed is a logon page. Therefore, after the logon page jumps to mainViewController, set mainViewController as the root View.
Another problem is that it is okay to select the view by clicking select photo to bring up the photo, but after selecting the image, the page will jump to the webview immediately, just like refreshing it. The error occurs because wkwebview cannot be loaded in viewDidAppear and must be loaded in viewDidLoad.
I have not found this problem for a long time on stackoverflow. Then, the more I checked the problem, the more complicated it was. Finally, I saw a post in the apple develop center to solve it.
Override func viewDidLoad () {self. view. addSubview (self. wk)} override func viewDidAppear () {// self. view. addSubview (self. wk) The webview can be loaded normally, but a Bug occurs when the image is uploaded.
}
So sometimes, you cannot complicate a simple problem.
Finally, the development environment: swift 3 iOS 10 Xcode 8