I searched alot for this but couldnt find a perfect answer.
My Ios app has its every page in UIWebview.
The only problem I am facing is when transiting from one page to another, the loading of UIWebview takes 1-2 seconds and the user sees a white background. Since all the html, css, image files are stored locally, how can I preload the UIWebview before transition? So that the user gets native feel.
I am loading the URL this way :
[self.navigationController setNavigationBarHidden:YES];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"start" ofType:#"html" inDirectory:#"main/html"]];
NSString *path = [url absoluteString];
NSURL *filePath = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#",path,#"?logged_in=1"]];
[self.webView loadRequest:[NSURLRequest requestWithURL:filePath]];
I am using a different viewcontroller for each page as I want the native push and modal transitions.
Related
I am using UIWebview to load a weburl, which contains few images and text. But after loading the url on webview images gets replaced with one another on some devices.
Is it problem with webpage?
My Code is here
NSURL *url=[[NSURL alloc]initWithString:_url];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
I have attach link to the actual loaded webview.
this image actually appears to some other location but right now it gets loaded to this place
Try to this one , it may help you..!!
https://github.com/AdrianFlorian/AFImageViewer
Images url are old, please replace with other like:
#image url: http://www.citi.io/wp-content/uploads/2015/10/1291-01-bruges-meteoweb.eu_.jpg
-(NSArray *)imageUrls
{
return [NSArray arrayWithObjects:
[NSURL URLWithString:#"http://imgs.mi9.com/uploads/landscape/4717/free-the-seaside-landscape-of-maldives-wallpaper_422_84903.jpg"],
[NSURL URLWithString:#"http://pics4.city-data.com/cpicc/cfiles42848.jpg"],
nil];
}
In my ios application, I am displaying a *.svg file as below:
NSString *path = [[NSBundle mainBundle] pathForResource:#"myFile" ofType:#"svg"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:path];
NSURLRequest *req = [NSURLRequest requestWithURL:fileURL];
[_webView setScalesPageToFit:YES];
[_webView loadRequest:req];
This works fine as I can load pinch and zoom the file on device. But now I need to highlight and area of image (say a room of a building or well of a garden). How can I achieve this? I have tried SVG Kit, but I was not able to find the touch-highlight area property. I've also used FSInteractiveMapView. But is does not allow me to pinch and zoom or scrol through the svg image. Please help me.
Let me start by saying I know how to load up an html file, but I need to load up index.html?mod=eurt. So the file itself is called index.html, but I need to load it with ?mod=eurt at the end. (the html file is shared between different applications and changing "?mod=X", will tell the file exactly what to do.
The problem is, I cannot figure out how to do this with the way I am loading up the html into the webview (I'm rather new at iOS development, so there may exist an easy way I don't know about). Here's what I have to load a local html file so far:
NSString *htmlFile=[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"
inDirectory:nil];
NSString *htmlString=[NSString stringWithContentsOfFile:htmlFile
encoding:NSUTF8StringEncoding error:nil];
[webView loadHtmlString:htmlString baseURl:nil];
I tried changing the ofType:#"html" to ofType:#"html?mod=eurt", but I didn't really expect that to work, and it didn't.
I've come from the land of Android where I simply did webView.loadUrl("file:///android_asset/index.html?mod=eurt");
There must be an easy way to do this in iOS, right?
You can do something like this
NSString* bundlePath = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"];
NSString* strUrl = [[urlToLoad absoluteString] stringByAppendingString:#"?mod=eurt"];
NSURL* urlToLoad = [NSURL URLWithString:strUrl];
[webView loadRequest:[NSURLRequest requestWithURL:urlToLoad]];
I've a problem that i couldn't solve, i wanna run the Apple - HTML5 Showcase - Gallary
in UIWebView inside my ipad app.
I've tried a local html file:
NSString *strr = [[NSBundle mainBundle] pathForResource:#"photo-gallery" ofType:#"html"];
NSString *str = [[NSString alloc] initWithContentsOfFile:strr encoding:NSASCIIStringEncoding error:nil];
NSLog(#"%#",str);
[webView loadHTMLString:str baseURL:nil];
and also a server html file, but it didn't work, can anyone help me, i wanna show an html5/css3 in UIWebView.
thx in advance.
hi this is what you can do
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:webFrame];
//getthe path of the local html file
NSURL *baseURL = [NSURL fileURLWithPath:fileNamePath];
NSURLRequest *aRequest = [NSURLRequest requestWithURL:baseURL];
//load the html file into the web view.
[aWebView loadRequest:aRequest];
//add the web view to the content view
[view addSubview:aWebView];
For server html you simply skip the second line, and put the address.
Hope it helps
You can take a look at phonegap. Its a complete framework for building html5 apps inside a UIWebview with native capabilities.
See: http://www.phonegap.com
I've got a view based application that one is at last just a single WebView ... with a Tabbar with some Icons.
So i need to add a small icon for go back to the localHTML File home.html.
Maybe could someone give me some informations how to handle it without change the view to a new one?
Here is how my other IBActions looks like
- (IBAction)news_button:(id)sender; {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.google.com"]];
}
Other option could be open a Website but not in safari ... like it does at the moment.
Thanks for sharing! :)
With the line above you are opening it in Safari right now.
You can get path to the local file if it is in main bundle catalog with
NSString *filePath = [[NSString stringWithFormat:#"%#/%#", [[NSBundle mainBundle] resourcePath], #"home.html"] retain];
So why not use
[yourWebView loadRequest:[NSURLRequest initWithURL:[NSUrl initWithString:filePath]]];