I am displaying a WebApp through WKWebView in Swift 3 (Xcode 8.3.3)
The WebApp is functioning as expected, except when I try to post an image to the server through the WebView.
The console from Xcode simply prints "Creating an image format with an unknown type is an error" without any further info to help me troubleshoot.
As this thread indicates, there might be something with alerts that is causing this issue. That the WebView is not set up correctly to display alerts and that this might cause an error.
However I have not been able to figure that one out by looking at the suggested solutions there.
In my viewWillAppear I call the function initWebView() which is set up like this:
func initWebView() {
let source: NSString = "var meta = document.createElement('meta');" +
"meta.name = 'viewport';" +
"meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';" +
"var head = document.getElementsByTagName('head')[0];" +
"head.appendChild(meta);" as NSString
let sourceScript: WKUserScript = WKUserScript(source: source as String, injectionTime: .atDocumentStart, forMainFrameOnly: true)
let addCookieScript="localStorage.setItem('device', '\(self.tokenFirebase)');"
let script: WKUserScript = WKUserScript(source: addCookieScript as String, injectionTime: .atDocumentStart, forMainFrameOnly: false)
// Create the user content controller and add the script to it
let userContentController = WKUserContentController()
userContentController.addUserScript(script)
userContentController.addUserScript(sourceScript)
// Create the configuration with the user content controller
let config = WKWebViewConfiguration()
config.userContentController = userContentController
let wkWebView = WKWebView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height), configuration: config)
wkWebView.translatesAutoresizingMaskIntoConstraints = true
self.wkWebView = wkWebView
wkWebView.restorationIdentifier = "wkWebView"
view.addSubview(wkWebView)
wkWebView.navigationDelegate = self
wkWebView.uiDelegate = self
let request : NSMutableURLRequest = NSMutableURLRequest(url: self.webUrl as URL)
wkWebView.isHidden = false
wkWebView.load(request as URLRequest)
}
I have been testing the app with the same results across iPhone SE (iOS 10) iPhone 7 (iOS 10) and iPad (iOS 9.3.3).
EDIT: The possible duplicate entry does not appear valid to me as it refers to implementing UIImagePickerController by code, but in my scenario it is the image picker that is created by the WKWebView which seems to cause this issue. However if I'm mistaken please guide me in the right direction :)
