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).
Related
I Checked Bootstrap framework's device/browser support page and found that it is not supporting WebView in iOS. I tried to find the reasons in internet but i am unable to find anything related to same.
If I include bootstrap in a webview project then will it be a problem?
Reference URL:
https://getbootstrap.com/docs/5.1/getting-started/browsers-devices/
Anyone know why my iOS app that uses a UIWebView which loads a form is ignoring all the form pattern and required rules? I don't think i need to post any code, as my app has many different forms all that work fine on any other browser.
For anyone looking the answer is here. UIWebViews do not support form validation or pattern rules.
html5 form validation not working in iOS UIWebView
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.
I'm now using Nexus 7 for my project which is using Server-Sent Events to get alert message.
On Nexus 7 Chrome browser, it works well.
But when I load the same page using webview, it does not work (saying "your browser does not support server-sent events...").
The source codes are exactly the same as [http://www.w3schools.com/html/html5_serversentevents.asp].
I think there maybe some difference between Chrome browser and Android Webview.
Could some one tell me how to make it work using Android Webview?
I think WebChromeClient is the one you need anyway. I am using both WebViewClient AND WebChromeClient because the latter one is full HTML5 enabled.
So in your Android WebView you can use BOTH Clients at the same time.
For instance
// clients
webView.setWebViewClient(new CustomWebViewClient(this));
webView.setWebChromeClient(new CustomWebChromeClient(this));
I use WebChromeClient for all the fancy stuff, like Javascript popups and yes, SSE using PHP scripts.
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