IOS development path (WKWebView embedded HTML5 Image Upload) 5,

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.