Load soap response to UIWebview Issue-iPhone - iphone

I want to show the soap response to UIWebview..
my soap response is,
<p><img src="http://img.gawkerassets.com/img/17u1vg3xyeuipjpg/xlarge.jpg" width="410" data-size="large"/></p><p><a rel="lytebox" href="http://img.gawkerassets.com/img/17u1vg3xyeuipjpg/original.jpg"> <p></a>Before sharing a playlist of songs with a crush was as simple as a few clicks, the mixtape was a labour of love; a time-consuming project. Every song was carefully considered. That’s all gone now, of course, but this DIY MP3 player conjured up by MakerBot can help bring it back.<img src="http://feeds.feedburner.com/r/GizmodoAustralia/4/zFs-k-3__1I" height="1" width="1"/>
like above..
am using this code for load the soap response to UIWebview
[webView loadHTMLString:soapresponse baseURL:nil];
in webview i want to clear the tags and display the contents.
anyone please help me to do this..
Thank you

EDIT Decoding HTML entities like & lt; to < : use NSString+HTML
NSString *strEncodeHTML = #"<p><img src="img.gawkerassets.com/img/17u1vg3xyeuipjpg/xlarge.jpg" width="410" data-size="large"/></p><p><a rel="lytebox" href="img.gawkerassets.com/img/17u1vg3xyeuipjpg/…; <a href="img.gawkerassets.com/img/17u1vg3xyeuipjpg/original.jpg" rel="modal"></a> <p></a>content here.img src="feeds.feedburner.com/r/GizmodoAustralia/4/zFs-k-3__1I" height="1" width="1"/>";
strEncodeHTML = [[[strEncodeHTML stringByReplacingOccurrencesOfString:#"<" withString:#"<"] stringByReplacingOccurrencesOfString:#">" withString:#">"] stringByReplacingOccurrencesOfString:#""" withString:#"\""];
NSLog(#"%#",strEncodeHTML);
NSString *strHTML = [NSString stringWithFormat:#"<html><body>%#<body></html>",strEncodeHTML] ;
[webView loadHTMLString:strHTML baseURL:nil];
Load html content like this:
NSString *strHTML = [NSString stringWithFormat:#"<html><body>%#</html>/<body>",yourSoapresponse];
[webView loadHTMLString:strHTML baseURL:nil];
Below given is example:
NSString *strHTML = [NSString stringWithFormat:#"<html><body><p><img src=\"http://img.gawkerassets.com/img/17u1vg3xyeuipjpg/xlarge.jpg\" width=\"410\" data-size=\"large\"/></p><p><a rel=\"lytebox\" href=\"http://img.gawkerassets.com/img/17u1vg3xyeuipjpg/original.jpg\"> <p></a>Before sharing a playlist of songs with a crush was as simple as a few clicks, the mixtape was a labour of love; a time-consuming project. Every song was carefully considered. That’s all gone now, of course, but this DIY MP3 player conjured up by MakerBot can help bring it back.<img src=\"http://feeds.feedburner.com/r/GizmodoAustralia/4/zFs-k-3__1I\" height=\"1\" width=\"1\"/></html>/<body>"];
[webView loadHTMLString:strHTML baseURL:nil];

Related

how to play video in iphone for which url is coming from service

I want to play video in my iPhone.
NSString *myHTML = [NSString stringWithFormat:#"\<html>\<head>\<body>\%#</body>\</html>", summary];//here summary is my url
[webView2 loadHTMLString:myHTML baseURL:nil];
if I give the url statically its working fine iam able to play the video,but my url is coming from server like this
<iframe width="560" height="314' src="http://www.youtube.com" frameborder="0" allowfullscreen></iframe> // iam getting this from service.
if I proceed in the same way to load video its not working it's just showing total string in my view.
how to rectify this issue shall I need to get only source from that string(url)or is there any other way?
here i may get youtube video or mp4 or mov but not flash.(ios doesn't suppor)
It looks like your Service Response is in XML Format. First of all you need to do is to perform XML Parsing. For XML Parsing there are several Tutorials available. Some of the Links are :
Super easy iOS XML parsing
Parsing XML with Objective-C
How to Parse XML Files in Xcode
After parsing, Extract the data you want and Store it in some Variables or Arrays. Then use that data to play the Video. You can check these Links :
YouTube API Blog
Playing Video on the iPhone and iPad
Be Relax. It's so simple. Just follow the above steps and you will get the Result you want.
Update :
If your string look like myString mentioned in the below example then you can use the below code to get the URL.
NSString *myString = #"<iframe width="560" height="314'' src="http://www.youtube.com" frameborder="0" allowfullscreen></iframe>";
NSRange firstRange = [myString rangeOfString:#"http://"];
NSRange secondRange = [[myString substringFromIndex:firstRange.location] rangeOfString:#"""];
NSRange finalRange = NSMakeRange(firstRange.location, secondRange.location);
NSString *subString = [myString substringWithRange:finalRange];
NSLog(#"subString :: %#",subString);
GoodLuck !!!
1. If you want to play video in MPMoviePlayerController then use bellow code...
you can play video in MPMoviePlayerController like bellow...
MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
videoPlayer.view.frame = CGRectMake(184, 200, 400, 300);
[self.view addSubview:videoPlayer.view];
[videoPlayer play];
see whole example from this link Code for Play Video in iPhone
Also see another Demo for play the video in iPhone from this link
AVPlayer
UPDATE :
2. If you want to play video in webView then use bellow code...
NSString *Str = #"<video controls> <source src=\"yourvideofile.mp4\"> </video>";
NSString *path = [[NSBundle mainBundle] pathForResource:#"yourvideofile" ofType:#"mp4"];
[Webview loadHTMLString:Str baseURL:[NSURL fileURLWithPath:path]];
i hope its useful to you...
just call add your string in this line your are good to go
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"Your string"]]];

Display RSS Feed in iPhone`

I have a list of RSS feeds and I need to display the detail of each feed in iPhone. I got all RSS feeds from the server which I'm displaying in tableview. Now on selecting a row I need to display the discription of RSS Feed which is coming from Server in HTML content like:-
<img border=\"0\" hspace=\"10\" align=\"left\" style=\"margin-top:3px;margin-right:5px;\" src=\"http://timesofindia.indiatimes.com/photo/4881843.cms\" />Cadila Pharmaceutical will seek the govt's nod in two days for initiating clinical trials for a vaccine against swine flu.<img width='1' height='1' src='http://timesofindia.feedsportal.com/c/33039/f/533968/s/1f181b11/mf.gif' border='0'/><div class='mf-viral'><table border='0'><tr><td valign='middle'><img src=\"http://res3.feedsportal.com/images/emailthis2.gif\" border=\"0\" /></td><td valign='middle'><img src=\"http://res3.feedsportal.com/images/bookmark.gif\" border=\"0\" /></td></tr></table></div><br/><br/><img src=\"http://da.feedsportal.com/r/133515347892/u/0/f/533968/c/33039/s/1f181b11/a2.img\" border=\"0\"/><img width=\"1\" height=\"1\" src=\"http://pi.feedsportal.com/r/133515347892/u/0/f/533968/c/33039/s/1f181b11/a2t.img\" border=\"0\"/>
How do I display this HTML Content in our iPhone UI, as this will contain text,hyperlink and images.
Is it proper way to use UIWebview in this case, as UIWebView is heavy weight.
Please read this blog : http://www.raywenderlich.com/2636/how-to-make-a-simple-rss-reader-iphone-app-tutorial,
It is useful for you.
you can do something like below.
first of all
descLbl.text=[self flattenHTML:descLbl.text];//descLbl.text is a text in which you are getting that HTML description...
now in flattenHTML method write like below...
- (NSString *)flattenHTML:(NSString *)html {
NSScanner *thescanner;
NSString *text = nil;
thescanner = [NSScanner scannerWithString:html];
while ([thescanner isAtEnd] == NO) {
[thescanner scanUpToString:#"<" intoString:NULL];
// find end of tag
[thescanner scanUpToString:#">" intoString:&text];
html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:#"\n"] withString:#" "];
// replace the found tag with a space
//(you can filter multi-spaces out later if you wish)
html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:#"%#>", text] withString:#" "];
} // while //
return html;
}
let me know it is working or not..
Happy coding!!!!
If you are planning to show HTML entities as it is, i would suggest to go with UIWebView. You can pass this HTML as a string in method loadHTMLString:
If you want the user to view the content as a web page, then loading the url in UIWebView is the best and easiest way.
Like this:
UIWebView *webView = [[UIWebView alloc] init];
NSURL *pageurl = [NSURL URLWithString:http://www.google.com];
NSURLRequest *request = [NSURLRequest requestWithURL:pageurl];
[webView loadRequest:request];
You can simply use RSSKit library.

cache html page at app loading

Is it possible to cache a html page at applicationDidFinishLauchingOptions() method so that when I want to implement UIWebView the delay taken for loading that html page can be avoided?
Any help would be appreciated.
You can get the data at the time of loading of app itself, and then convert that to NSString or keep that as NSData. After that later when you want to load the page you use like -
For NSString -
NSString *htmlString = // string content
[webView loadHTMLString:htmlString baseURL:baseURLString];
for NSData -
NSData *htmlData = // data content
[webView loadData: MIMEType:#"" textEncodingName:#"" baseURL:#""];

iphone: how to get text from web site and show it on application

i have web site that show a text and i update this text every day , i want to show this text on iphone application , how can i get this text from web site from application ?
what should i do ?
thanks
1-> you require to connect with your web server thought HTTP connection.
2-> Make the request to server.
3-> Parse server response that may contain your "Text".
For technical assistance Read below.
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html
I don't recommend this as the best way to obtain a string from your own web server.
This should point you in the right direction, don't expect it to compile cleanly.
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
/* set headers, etc. on request if needed */
[request setURL:[NSURL URLWithString:#"http://example.com/whatever"]];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL];
NSString *html = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
NSScanner *scanner = [NSScanner scannerWithString:html];
NSString *token = nil;
[scanner scanUpToString:#"<h1>" intoString:NULL];
[scanner scanUpToString:#"</h1>" intoString:&token];
This will capture text from first h1 tag.
The simplest way is to create a REST API. That might sound tough but it's really easy. On the server side, create a new page which holds only the raw text. Usually it's best to keep it there in JSON/XML format, but a simple text will also work. Now from the iPhone, just contact that address and the response data will contain the text. Parsing an existing page is not something I recommend, because changing that page in the future might result in the app not working anymore.
This is a answer quite late but I think it still might help in your future. You can go into parsing the website and that is the right way to do it but I will show you how to do it a different way, this can also be used to read xml, html, .com, anything and also, .rss so it can read RSS Feeds.
Here :
This can get your first paragraph, if you request I will show you how to get the second paragraph and so on.
//This is your URL
NSURL *URL = [NSURL URLWithString:#"URL HERE"];
//This is the data your pulling (dont change)
NSData *data = [NSData dataWithContentsOfURL:URL];
// Assuming data is in UTF8. (dont change)
NSString *string = [NSString stringWithUTF8String:[data bytes]];
//Your textView your not done.
description.text = string;
//Do this with your textview
NSString *webStringz = description.text;
// Leave this
NSString *mastaString;
mastaString = webStringz;
{
NSString *webString2222 = mastaString;
NSScanner *stringScanner2222 = [NSScanner scannerWithString:webString2222];
NSString *content2222 = [[NSString alloc] init];
//Change <p> to suit your need like <description> or <h1>
[stringScanner2222 scanUpToString:#"<p>" intoString:Nil];
[stringScanner2222 scanUpToString:#"." intoString:&content2222];
NSString *filteredTitle = [content2222 stringByReplacingOccurrencesOfString:#"<p>" withString:#""];
description.text = filteredTitle;
}
Title ? Same deal change the <p> to a <title> in RSS <description> and <title>.
Image ? Same deal change the <p> to what ever your RSS or website uses to get a image to find
But remember for both of them when you change the` you see the link which says stringByReplacingOccurences of you have to change that as well.
out then you have to delete this and make your code like this :
/This is your URL
NSURL *URL = [NSURL URLWithString:#"URL HERE"];
//This is the data your pulling (dont change)
NSData *data = [NSData dataWithContentsOfURL:URL];
// Assuming data is in UTF8. (dont change)
NSString *string = [NSString stringWithUTF8String:[data bytes]];
//Your textView your not done.
description.text = string;
NLog(#"%#", string)
//Do this with your textview
NSString *webStringz = description.text;
// Leave this
NSString *mastaString;
mastaString = webStringz;
Now check your log it shows your whole website html or rss code then you scroll and read it and find your image link and check the code before it and change the String Scanner to your needs which is quite awesome and you have to change the stringByReplacingOccurences of.
Like I said images are a bit tricky when you do it with this method but XML Parsing is a lot easier ONCE you learn it , lol. If you request I will show you how to do it.
Make sure :
If you want me to show you how to do it in XML just comment.
If you want me to show you how to find the second paragraph or image or title or something just comment.
IF YOU NEED ANYTHING JUST COMMENT.
Bye have fun with code I provided, anything wrong JUST COMMENT! !!!!
:D

Load YouTube GData feed for a single video by id

I am trying to play a youtube video in a UIWebView instead of leaving my application.
Google thinks is easy peasy- http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html
So I have the GData framework and headers working nicely, and I have no problem doing queries, loading user's video feeds etc.
But what I can't seem to do is load a specific video's feed. I know the ids of the videos that I want the feeds for in advance. How do i load a specific video's feed?
I'm then going to follow google's instruction :
Grab the video url from the media tag in the API response with the application/x-shockwave-flash type.
and then embed it like so:
// webView is a UIWebView, either initialized programmatically or loaded as part of a xib.
NSString *htmlString = #"<html><head>
<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head>
<body style=\"background:#F00;margin-top:0px;margin-left:0px\">
<div><object width=\"212\" height=\"172\">
<param name=\"movie\" value=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"></param>
<param name=\"wmode\" value=\"transparent\"></param>
<embed src=\"http://www.youtube.com/v/oHg5SJYRHA0&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"
type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"212\" height=\"172\"></embed>
</object></div></body></html>";
[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:#"http://www.your-url.com"]];
Any help would be much appreciated!
Given a feed of YouTube video entries, you can get the IDs and Flash URLs from each entry this way:
for (GDataEntryYouTubeVideo *videoEntry in [feed entries]) {
GDataYouTubeMediaGroup *mediaGroup = [videoEntry mediaGroup];
NSString *videoID = [mediaGroup videoID];
NSArray *mediaContents = [mediaGroup mediaContents];
GDataMediaContent *flashContent =
[GDataUtilities firstObjectFromArray:mediaContents
withValue:#"application/x-shockwave-flash"
forKeyPath:#"type"];
NSLog(#"video ID = %#, flash content URL = %#",
videoID, [flashContent URLString]);
}
In exactly the same situation just found the answer. Typically of many large APIs, common usage instructions get lost in explanation of the higher level stuff - can be frustrating. Thankfully, the info is there...
http://code.google.com/apis/youtube/2.0/developers_guide_protocol_video_entries.html
So, we should be able to plug the returned ATOM feed into the GData library and have it parse out the proper content URL for use in the 'UIWebView' style player code.
...Grobbins, read the question properly next time!