My team of developers has built a successful iOS universal app which synchronizes sophisticated HTML5 web apps to an iPhone / iPad. The apps are loaded into the UIWebView from the local file system. We recently added in-app email using MessageUI.framework.
Everything was going fine until our QA department identified a use case where the instantiation of the MailCompose class causes the UIWebView to throw a SECURITY_ERR: DOM Exception 18 error. This ONLY occurs on iOS 4.2.1. The app functions normally when built against SDK 4.1 and installed on a device running iOS 4.1. This FEELS like either an iOS 4.2 bug, or an HTML5 issue that has appeared in iOS 4.2.
I am looking for techniques to find the cause of the SECURITY_ERR: DOM Exception 18. I know that this error is a same-origin exception of some kind, but it doesn't make sense why it works on 4.1 but not 4.2. And why does the MailCompose class cause the issue?
Any help at all will be greatly appreciated!
may I ask how do you load your html source from the local FS ?
Also what does your MailCompose class do, to interact with the document loaded into the UIWebView ?
If you are reading the contents of an html file into a string and then load it into the UIWebView, then you have to change 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 ahead and load the actual html file via an 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];
Doing so, enables access to window.localStorage, window.openDatabase and other objects.
Cheers
Related
ScreenShot.png
I use UIWebview to load a remote page generated by nodejs.
[self.webview loadRequest:request];
Page is rendered correctly in the first load, but not rendered and the UIWebview shows weird HTML source code after reload. I tried to change any kind of cache policy, but is still not able to fix it.
Anyone encountered same issue before?
Many Thanks.
I'm trying to write a mobile app using Adobe AIR which shows a web page.
I just want to show the web page and allow the user to browse it.
The problem is when I try to do it I'm getting lots of Javascript errors and the page is partially rendered but in an unreadable way.
I've tried to pass true to the useNative ctor parameter but it didn't seem to make any difference.
Is there a way to display HTML content from the web in Adobe AIR without using ANE?
You don't need an ANE to allow users to browse a web page with Adobe AIR. Using a webView is the best, simple, popular way.
webView.stage = this.stage;
webView.viewPort = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
webView.loadURL("http://www.example.com");
Your problem is not the ActionScript code you developed. It's the page that your are loading into your webView element. If the page has Javascript errors with your webView, it probably has Javascript errors using a simple browser on your mobile device (or even on a desktop). Thus, passing True to useNative will not solve your problem.
To solve this problem, run the app in debug mode and look for the Javascript errors in the debug console. For me, for example, the Javascript command console.log function was unrecognized by the webView and broke many parts of my Javascript execution in my pages. Go through each of the Javascript errors appearing and fix them, until your page runs smoothly.
Does anyone knows if I can have an deep link in my iOS app to wechat account? I have an developer account with wechat (Chinese acc) just want to check if there are ways to deep link wechat account in my iOS app. So is there a way to deep link in my iOS app to wechat account chat?
You can use the url schemes to open another iOS Apps from your iOS app.
Find below code to open the wechat app from your app when pressing button.
- (void)buttonPressed:(UIButton *)button
{
NSString *customURL = #"weixin://";
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:customURL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"URL error"
message:[NSString stringWithFormat:#"No custom URL defined for %#", customURL]
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
}
refer Apple documentation
Another SO Answer.
I have to display HTML text in Label & UITextView in my app.
In iOS 7 it works fine as following:
NSMutableAttributedString * attrStr = [[NSMutableAttributedString alloc] initWithData:
[HTMLstr dataUsingEncoding:NSUnicodeStringEncoding] options:
#{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}
documentAttributes:nil error:nil];
But it will crash my app if I used same method in iOS 6.
Thanks
NSHTMLTextDocumentType is available only in iOS 7.0 and later.
Reference: NSAttributedString_UIKit_Additions
Checkout https://github.com/Cocoanetics/DTCoreText, what it does is to display all kinds of html content in all kinds of native iOS controls, and it is actively being maintained.
I just added it in my project so I am pretty sure it is what you need. You can easily start using it by looking at the demo project.
BTW, it supports iOS6 (tested in my project) and prior (not tested).
My iOS app needs to work completely offline if the user downloads all the data. Some views are mobile websites, so all I do when a user views a website online is download the URL from the database and display that in a UIWebView.
However when the user decides to download all the data for offline usage I need to display that webpage offline.
I tried
NSData *myPagedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://www.domain.nl/"]];
and then display that data in an UIWebView
[_webView loadData:myPagedata MIMEType:#"text/html" textEncodingName:#"UTF-8" baseURL:nil];
But that doesnt save CSS and images.
I also found out that ASIWebPageRequest can do this but thats a dead project. Does anybody know how I can display a webpage offline with CSS and images?
You might take a look at AFCache. https://github.com/artifacts/AFCache
I have not tried this library but it looks promising.