how to pass local html files using array in xcode - ios

here i am trying for a application,
when i click on the table view it will redirect to another page called details. there I have used a webview to dispaly the selected url value.
here is my code
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
self.navigationItem.title=#"sample";
servicesArray=[[NSMutableArray alloc]init];
[servicesArray addObject:#"1"];
[servicesArray addObject:#"2"];
[servicesArray addObject:#"3"];
urlsArray=[[NSMutableArray alloc]init];
[urlsArray addObject:#"http://www.google.com"];
[urlsArray addObject:#"http://www.yahoo.com"];
[urlsArray addObject:#"http://www.facebook.com"];
}
here instead of urls link i want to pass my local html files. can you please help me out
Thanks
chintu.

try like this,take all the html file names in Array yourArray.
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:[yourArray objectAtIndex:selectedIndex] ofType:#"html" inDirectory:nil];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[WebView loadHTMLString:htmlString baseURL:nil];

Related

viewcontroller using a NULL baseURL argument with the loadHTMLString baseURL method : data theorem

I am facing the problem "MyViewcontroller using a NULL baseURL argument with the loadHTMLString baseURL method : data theorem"- i have successfully completed my task and all are working fine.
The Issue was in the OSWAP security scan for vulnerability it shows the above error.
My code snippet:-
NSString *aHtmlString = kEmptyString;
// Getting the bool from configuration plist
NSString *thePlistPath = [[NSBundle mainBundle] pathForResource:#"config" ofType:#"plist"];
NSDictionary *theURLdata = [[NSDictionary alloc] initWithContentsOfFile:thePlistPath];
is
ServerFAQAvailable = [[theURLdata valueForKey:kIsServerFAQAvailableKey] boolValue];
if (one || two || three) {
aHtmlString = [self loadFAQFor];
} else {
aHtmlString = [self loadFAQForwithout];
}
NSURL *baseURL = [NSURL fileURLWithPath:thePlistPath];
[self.faqWebView loadHTMLString:aHtmlString baseURL:baseURL];
Update:
if (one || two || three) {
aHtmlString = [self loadFAQFor];
} else {
aHtmlString = [self loadFAQForwithout];
}
NSURL *baseURL = [NSURL fileURLWithPath:#"about:blank"];
[self.faqWebView loadHTMLString:aHtmlString baseURL:baseURL];
Still shows me scan issue
The issue is the baseURL: parameter. BaseURL isn't needed for an html string, it is usually used for relative links. If all you're trying to do is show some html, are you sure you need it?
The security issue flagged makes sense (my understanding, roughly): If a webview's baseURL is set to the local file system, then a page loaded (eventually) through that webview could access local resources.
Try passing nil for baseURL: should silence this warning.
baseURL should be [[NSBunld mainBunld] bunldPath], you can try like this..
NSString *path = [[NSBundle mainBundle]bundlePath];
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:self.htmlName ofType:#"html"];
NSString *htmlContent = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:path]];

How to set image into uiwebview?

I have created a html code like see above and the code uploaded to http://www.ged.Ic.com site.
Added an image name “1.jpg” into Xcode project.
When open iPad app loading http://www.ged.Ic.com/page/ from webview.
How to get to set image from into Xcode project to img src="image path from xcode"
NSString *imageFileName = #"image";
NSString *imageFileExtension = #"png";
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageFileName ofType:imageFileExtension];
NSString *imgHTMLTag = [NSString stringWithFormat:#"<img src=\"file://%#\" />", imagePath];
NSString *imageUrlString = #"http://www.gstatic.com/translate/intl/ru/logo.png";
NSString *yourText = #"Some text here";
NSString *htmlString = [NSString stringWithFormat:#"<img src='%#'/><br><b>%#</b>", imageUrlString, yourText];
[myWebView loadHTMLString:htmlString baseURL:nil];

Load local html files using array [duplicate]

here i am trying for a application,
when i click on the table view it will redirect to another page called details. there I have used a webview to dispaly the selected url value.
here is my code
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
self.navigationItem.title=#"sample";
servicesArray=[[NSMutableArray alloc]init];
[servicesArray addObject:#"1"];
[servicesArray addObject:#"2"];
[servicesArray addObject:#"3"];
urlsArray=[[NSMutableArray alloc]init];
[urlsArray addObject:#"http://www.google.com"];
[urlsArray addObject:#"http://www.yahoo.com"];
[urlsArray addObject:#"http://www.facebook.com"];
}
here instead of urls link i want to pass my local html files. can you please help me out
Thanks
chintu.
try like this,take all the html file names in Array yourArray.
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:[yourArray objectAtIndex:selectedIndex] ofType:#"html" inDirectory:nil];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[WebView loadHTMLString:htmlString baseURL:nil];

Need to take item from rss and open it in WebView

Hey this is my code on rootviewcontroller.m (the rss page)
NSDictionary* storyLink = [[stories objectAtIndex: storyIndex] objectForKey: #"link"];
// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:#" " withString:#""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:#"\n" withString:#""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"link: %#", storyLink);
browserScreen=[[BrowserViewController alloc] initWithNibName:#"BrowserViewController" bundle:nil];
browserScreen.storyLink =[[stories objectAtIndex: storyIndex] objectForKey: #"link"];
[self.view addSubview:browserScreen.view];
This opens WebView page but does not loads the url I requested. Here's my BrowserViewController.m s viewDidload page(web view and i also patched up things at .xib file)
- (void)viewDidLoad
{
[super viewDidLoad];
// NSString *urlAddress = storyLink;
NSString *urlAddress = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:#"storyLink"];
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
// Do any additional setup after loading the view from its nib.
}
Hope someone helps because I feel desperate about it
I assume this code reflects a lot of flailing because you compute a local storyLink, clean it up, log it, then ignore it; you set the storyLink property of browserScreen from the original, un-cleaned-up source; then, in -viewDidLoad, you don't even use that, you get a file path from your bundle.
For that last part: given that you have a file path string, you shouldn't use +URLWithString: to create a URL from it. A file path is a not a valid URL string. You need to use +fileURLWithPath:.
Also, you compute the file path as being immediately inside your bundle. Is that really where the file is? It's not in Contents/Resources or something like that?

Split View App, display PDF's in the Detail View, PDF's are local storage

I have a Split View App that I am building, using a plist for my Array, and using a UIWebView to display content in the DetailViewController. Using the below code to make calls to the URL address in my plist, and the URL Address is displaying a PDF in the DetailViewController through the UIWebView.
DetailViewController.m
NSString *mutareURL = [_detailItem description];
NSURL *url = [NSURL URLWithString:mutareURL];
[_catalog loadRequest:[NSURLRequest requestWithURL:url]];
What I need to do is have all of the PDF's in my resource folder in my project. I can use an NSArray or plist for the RootViewController (TableView), but I need to have the ability to display the PDF's in the DetailViewController through the UIWebView when a Row is selected in the RootViewController (TableView). I tried this Code in my DetailViewController.m file, but it is not working.
NSString *path = [[NSBundle mainBundle] pathForResource:#"%#" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[_Pdf loadRequest:request];
I have an NSLog in my RootViewController.m file with this code, and i do see that the names of the pdf files are showing up in my debugger. I just do not know how to get them from the RootViewController and pass them into the pathforResourse"#"%#" ofType:#"pdf"]; area. brochures is an NSArray that has all of the addObject:#"nameofpdfs" that is passing.
RootViewController.m
detailViewController.detailItem = [NSString stringWithFormat:#"%#", [brochures objectAtIndex:indexPath.row]];
NSLog(#"Cell created for row: %d", [indexPath row]);
NSLog(#"brochures = %#", detailViewController.detailItem);
Thank you
The answer is probably in the last snippet. The first line essentially passes the selected filename from the RootViewController to the DetailViewController by setting the latter's detailItem property.
If you replace
NSString *path = [[NSBundle mainBundle] pathForResource:#"%#" ofType:#"pdf"];
by
NSString *path = [[NSBundle mainBundle] pathForResource: self.detailItem ofType:#"pdf"];
it should work.
Depending on whether the filenames in the brochures array already contain the #".pdf" suffix, you might have to leave it out of the message send:
NSString *path = [[NSBundle mainBundle] pathForResource: self.detailItem ofType: nil];

Resources