UIWebView: Images are not updating - iphone

I am using UIWebView to load HTML Page. From that HTML I have generated PDF file. My PDF file content changes as per the HTML data changes. when I change the Signature(Image) of the user in application respective PDF will not change to new signature. It shows the previous signature.
How can I reload that UIWebView?

[webView reload] should do the trick.
If you are using a new URL you can use [webView loadRequest:[NSURLRequest requestWithURL:theURL]];

If you are using same url with updated content use this.
UIWebView* webV=[[UIWebView alloc]init];
NSString* htmlString= #"Loading...";
[webV loadHTMLString:htmlString baseURL:nil];
[webV loadRequest:[NSURLRequest requestWithURL:mainURL]];

Related

Why my page downloaded to folder Documents of iPhone simulator is not loadable?

I made an hybrid app between objective C and javascript. My app works so:
When I press on the first button it will load a UIWebView
In this UIWebView I can save the html to the Documents folder
When I save the website I create a JSON to store informations and I save this JSON to Documents folder
When I press the second button, it will load another UIWebView in which there are a mobile site that read informations from JSON and present this data in a html list
When I press on the name of one site it will load the site from Documents folder
The first 4 points works great, but when I press on the site title I've trouble, indeed, the UIWebView shows me a page in which there are written that the page it's not stored on this server. When I navigate with Finder to the Documents folder of my app and I double click on the html site it shows me it in Safari. Why when I load it with an UIWebView doesn't work? I will post here a screenshot to understand my flow.
CODE: I post here the code to load the html:
viewDidLoad method where I call the method to load my page
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.webView.delegate = self;
//[self loadWebsite:#"http://localhost/root/main/index.html"];
[self loadWebsite:#"http://192.168.2.1/root/main/index.html"];
}
loadWebsite method
-(void)loadWebsite:(NSString*)site
{
NSURL *url = [NSURL URLWithString:site];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView setScalesPageToFit:YES];
[self.webView loadRequest:request];
}
This seems like a problem with how you are loading your html file into the webview. You should post the code where you are loading the uiwebview.
To load a webview with a local file use the following code :
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"htmlfilename" ofType:#"html" inDirectory:#"Documents"]];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
You can refer to this post : Load resources from relative path using local html in uiwebview

How to reload already loaded uiwebview with new HTML string?

I have implemented UIWebView in my project to show some HTML data. The problem is I have loaded the webview with some HTML string by using the method
[myWebView loadHTMLString:Data baseURL:nil];
Now I want to add action of button such that when user click on the button the new data is loaded in the webview. such that
-(void)clicked{
[myWebView loadHTMLString:newData baseURL:nil];
}
I tried by applying the same as above but no affect was there. I also tried [myWebView reload], but nothing happened.
Plz tell me the appropriate method.
TRy with, First call stopLoading then reload on your UIWebView instance.
[myWebView stopLoading ];
[myWebView reload];
loadHTMLString:baseURL: is the correct method.
But still some things might be wrong, such as the data you are trying to send to the webview. Did you try logging your newData object to see what is being send to the webView object?
Is your newData string loaded from a resource file? If so, you could try loading you html data from the resources with something like the code bellow
NSString *html = [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"myFileName" ofType:#"html"]];
[myWebView loadHTMLString:html baseURL:nil];
Even after trying accepted answer I have not got my issue solved.
So, after spending some time I found below logic which works for me:
Objective-c
dispatch_async(dispatch_get_main_queue(), {
[myWebView reload];
})
Swift
dispatch_async(dispatch_get_main_queue(), {
myWebView.reload()
})

display html embedded data in iphone

I'm wondering whether there's a control to display html embedded data in iphone. I need to display the information as it is on the web. The data is saved into it database together with its html tag.
So is there anyway for me to display the data accordingly..
You can use a UIWebView and load HTML using
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
you can use a UIWebView and loadHTMLString method to load the data in HTML.
You can also change html page contents at run time using the javascript.
You can use webview for displaying displaying html embbed data.
Example is given here :
To load remote html file:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.apple.com"]]];
To load local html file:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"index" ofType:#"html"]isDirectory:NO]]];
To load html string:
[webView loadHTMLString:#"<img src=test.png>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];

How to open web page in web view on iPhone

I want to open web page on the webView by passing the web url of that page. How is this possible?
You can load a website using this:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://i.wrightscs.com"]]];
You can also load HTML into a UIWebView using this:
[webView loadHTMLString:#"<strong>It Work's!</strong>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];

iPhone - How to preload a local file in a UIWebView?

Is it possible to preload content of a local file with embedded images for a UIWebView?
This is how I'm loading the data inside the UIWebView:
NSString *urlString = [[NSBundle mainBundle] pathForResource:#"info" ofType:#"html"];
NSString *htmlContent = [NSString stringWithContentsOfFile:urlString encoding:NSUTF8StringEncoding error:nil];
[myWebView loadHTMLString:htmlContent baseURL:nil];
But the UIWebView still needs some time to display the content. Is there any way to put this content into the browser cache on app start?
If you create the browser object on app start and load the HTML string immediately, it should work fine to display the view later.
Another option would be to allocate it when necessary, but not actually show the view until it's done loading (wait for - (void)webViewDidFinishLoad:(UIWebView *)webView to be called on the web view's delegate before showing it).
Also, would it make more sense to call
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:urlString]]];
than using the loadHTMLString: method? That way, you don't have to load the HTML string into memory yourself and the web view can load it directly from disk.