How to troubleshoot iOS UIWebView DOM Exception 18?

My development team has built a successful universal iOS application that synchronizes complex HTML5 web applications with iPhone / iPad. Applications are loaded into the UIWebView from the local file system. We recently added an email using MessageUI.framework.

Everything went well until our QA department set a precedent when an instance of the MailCompose class caused the UIWebView to throw the SECURITY_ERR: DOM Exception 18 error. This ONLY happens on iOS 4.2.1. The application works fine when it is built on the SDK 4.1 and installed on a device running iOS 4.1. This is FEELS, like the iOS 4.2 bug, or the HTML5 issue that appeared in iOS 4.2.

I am looking for methods to find the reason for SECURITY_ERR: DOM 18 exception. I know that this error is an exception of the same origin, but it does not make sense why it works on 4.1 but not 4.2. Why does the MailCompose class cause this problem?

Any help at all would be greatly appreciated!

+4
source share
1 answer

may I ask how do you load your html source from local FS? Also, what does your MailCompose class do to interact with a document loaded in UIWebView?

If you read the contents of the html file in a line and then load it into a UIWebView, you need to modify it and load it using the file:// protocol.

Instead of loading the html source as a string:

 NSString *html = [NSString stringWithContentsOfFile:[path stringByAppendingString:@"path to the html file"] encoding:NSUTF8StringEncoding error:NULL]; [webView loadHTMLString:html baseURL:baseURL]; 

Go and download the actual html file via NSURLRequest (file: // url)

 NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *baseURL = [NSURL fileURLWithPath:[path stringByAppendingString:@"path and file name of the file"]]; NSURLRequest *request = [NSURLRequest requestWithURL:baseURL]; [webView loadRequest:request]; 

By doing this, allows access to window.localStorage, window.openDatabase and other objects.

Greetings

+2
source

Source: https://habr.com/ru/post/1335343/


All Articles