Need to take item from rss and open it in WebView - ios

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?

Related

Post image from local bundle to PinInterest iphone.

I have implemented the PinInterest through web view using this code:
NSString *description = #"Post your description here";
NSURL* sUrl = [NSString stringWithFormat:#"http://4.bp.blogspot.com/-w4oTZjlpgwo/T5_pi-KJPuI/AAAAAAAAAoM/rKm3E0XCbgY/s1600/red_rose_flower3.jpg"];// pass your link here with your image name
// NSLog(#"URL:%#", sUrl);
NSString *protectedUrl = ( NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,( CFStringRef)sUrl, NULL, (CFStringRef)#"!*'\"();:#&=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
NSLog(#"Protected URL:%#", protectedUrl);
NSString *imageUrl = [NSString stringWithFormat:#"\"%#\"", sUrl];
imageUrl=[[NSBundle mainBundle]pathForResource:mAppDelegate.imagename ofType:nil];
NSString *buttonUrl = [NSString stringWithFormat:#"\"http://pinterest.com/pin/create/button/?url=www.flor.com&media=%#&description=%#\"", protectedUrl, description];
NSMutableString *htmlString = [[NSMutableString alloc] initWithCapacity:1000];
[htmlString appendFormat:#"<html> <body>"];
[htmlString appendFormat:#"<p align=\"center\"><img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></p>", buttonUrl];
[htmlString appendFormat:#"<p align=\"center\"><img width=\"300px\" height = \"400px\" src=%#></img></p>", imageUrl];
[htmlString appendFormat:#"<script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"></script>"];
[htmlString appendFormat:#"</body> </html>"];
return htmlString;
And I have also tried using PinInterest iOS SDK, but all I found is that can only pin the image from url.
And I need to pin image from local bundle image. Any help will be greatly appreciated.
Read the document once, they said Right now, "we only support pinning an image from a url. In the future, we’ll add support for pinning local images." i think this answers your question. for more clarification reed this. hope this helps :)

I need to format and display specified contents from the URL in webView

I am creating an RSS feed app , i need to format the Feeds in webView and display only description .
Here is the code:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *myURL = [NSURL URLWithString: [self.url stringByAddingPercentEscapesUsingEncoding:
NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:myURL];
[self.webView loadRequest:request];
}
Instead of loading all contents of the specified URL i need to format and display only the "description" of the RSS Feed.
I have parsed my data i only need to format it in the web view .
The code for parsing (prepareForSegue):
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSString *string = [feeds[indexPath.row] objectForKey: #"link"];
NSLog(#"Description : %#" , string);
[[segue destinationViewController] setUrl:string];
}
}
From the question it seems that you require to parse that response first.
NSURL *url = [NSURL URLWithString:#"http://www.google.co.in/search?q=search"];
NSString *webData= [NSString stringWithContentsOfURL:url];
NSLog(#"%#",webData);
This code will store your html page into NSString after getting this, parse this string same like normal XML parsing using html tags and get the required data out of this.
Here is a code to load string back to UIWebView as in HTML format:
If you literally want to load an HTML string, try this:
NSString *embedHTML = #"<html><head></head><body><p>Provide your display data here in HTML format</p></body></html>"; // in your case it is description data
[webView loadHTMLString: embedHTML baseURL: nil];
Hope this is what you are looking for.

how to pass local html files using array in xcode

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];

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];

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