Using Youtube in iPhone - iphone

I have never use youtube api in iPhone ...I tried to use GData but was missed in some steps here are link ans tutorial ....So never implemented it...
Due to which i used RSS feed and load it on tableView ...
and when user click on any row then the actual webPage opens in WebView and user have to click on the video to run it....
But now i don't want this ....
Can anyone provide me a better solution....
Thanks...

As I have given a brief answer here
I am explaining it in detail:
Put a button of same size and without any background image over your webview.
When the user presses this button open a new modal view with only a full screen size webview in it.
Pass the same html string to load the webview (that you were passing in your smaller webview).
Pass the touches programmatically to the webview like:
– (void) touchTheWebViewProgrammatically{
for(UIView* vw in [webView subviews]){
if([vw isKindOfClass:[UIButton Class]])
[vw sendActionsForControlEvents:UIControlEventAllEvents];
}
}

Related

While clicking on some links on UIWebview it's automatically connect(go) to the itunes. but cannot get back to the app after clicking a iTunes link

Here we are using UIWebview related application.
while clicking on some links, it's automatically connect(go) to the itunes.
but it's cannot get back to the app after clicking a itunes link (with out clicking on Exit).
My Question is, how can come back to the app after clicking a itunes.
Try this one uiwebview delegate method.
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL* url = [request URL];
if (UIWebViewNavigationTypeLinkClicked == navigationType)
{
[[UIApplication sharedApplication] openURL:url];
return NO;
}
return YES;
}
I usually insert a button next to UIWebView.
Use a new view and insert button in any corner of view and then put your UIWebView, set your uiwebview is not fit to screen so you can push to exit button. When you tap to button than hide your view. ITs usually what i do for such situation, maybe it can help to you
When you click on any link and you now go to at this link of page and if you want to go previous to your application. Generally You can not go Back to your Application because Apple iOS does not provide this types of feature.
I am not sure but It may be possible in JB Device.
you can add custom tool bar at the top of your view and add back button to custom tool bar to come back to your app. Below to custom tool bar add your webview.Hope it will helps you.
If you are loading the webpage with Safri or you are opening iTunes app with custom schema, it is not possible, because you are leaving the app.
But yes you can do this, If you will load that itunes connect link through web view, and there you can place a custom back button to come back to your previous page.
For Example :
UIWebView *webView=[[UIWebView alloc]init];
[self.view addSubview:webView];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.xyz.com"]]];

How to detect the user click a hyper-link

My app will display some text, and I want to make the hyper-link be able to be clicked. I have some questions about this feature.
How do I parse the text to be aware this is a link?
Once a user click the link, I don't want the OS to switch to Safari and open the link, this is very bad because the user can not go back to my application. So I want to open the link within my application. As soon as the user click the link, my app will present a view modally to display the web content. Any advice would be appreciated.
You probably want to subclass UILabel. When you change the text, have it try to see if the text is a hyperlink, if it is, set it to enable user interaction and change the text color to blue. When the user taps on the link, send a message to the main view controller (Possibly through delegation) to open the link.
to display web content in your app, look into UIWebView.
If your text can be formatted as html with hyperlinks (<a> tags), you could use a UIWebView to display it.
The UIWebViewDelegate's webView:shouldStartLoadWithRequest:navigationType: method is called when a user taps a link. Usually you would make your controller implement this method, and set the UIWebView's delegate to the controller.
You're going to want to check out a Github project called LRLinkableLabel.
It will auto-detect any URLs that are inside the .text property.
You can use it like so:
LRLinkableLabel *label = [[LRLinkableLabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 20.0)];
label.delegate = self;
label.text = #"Check out http://dundermifflin.com to find some great paper deals!";
Then just make sure self implements this method:
- (void) linkableLabel:(LRLinkableLabel *)label clickedButton:(UIButton *)button forURL:(NSURL *)url {
[[UIApplication sharedApplication] openURL:url];
}
You can also use the linkColor and textColor properties to configure the appearance of the label. From this point you can use it just like any other UILabel.
Remember to set the delegate to nil when you're all done to make sure everything is all cleaned up.
Hope this helps.

is it possible to use iframe in UIWebView?

i want to add a facebook like button in my app. in developer.facebook.com i couldn't fine anything about that. is it possible to use iframe created by facebook like button in UIWebView? it think if its possible then i can add a UIWebView in my app which use that iframe. thanx. please write some example code.
Yes it is possible, I am using iFrame to load youtube Video inside the app.
Following simple steps will guide you to achieve it.
Step 1 : Create a UIWebView in xib
Step 2 : Connect it to your ViewController's .h file. (I am referring it as _wevView in my project).
Step 3 : Create a method embedYouTube in your ViewController's .m file.
-(void)embedYouTube {
// Read create a NSString object with iframe
NSString *embedHTML = #"<iframe width=\"300\" height=\"250\" src=\"http://www.youtube.com/embed/rOPI5LDo7mg\" frameborder=\"0\" allowfullscreen></iframe>";
// Initialize the html data to webview
[_webView loadHTMLString:embedHTML baseURL:nil];
// Add webview to your main view
[self.view addSubview:_webView];
}
Step 4: Add the webview to your main view by by making a call to the method embedYouTube inside viewDidLoad
[self embedYouTube];
Step 5: Compile and run the app. You should be able to view the YouTube player embedded in the page.
Yes that is possible you can use the iframe in webview. You need to load the webview with the HTML string. You can also find the related code of HTML for iframe if you search over the net. Moreover you can also use javascript, in webview using the method stringByEvaluatingJavaScript: of UIWebview.

Reused UIWebView showing previous loaded content for a brief second on iPhone

In one of my apps I reuse a webview. Each time the user enters a certain view on reload cached data to the webview using the method :-
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)baseURL
and I wait for the callback call
- (void) webViewDidFinishLoad:(UIWebView *)webView.
In the mean time I hide the webview and show a 'loading' label.
Only when I receive webViewDidFinishLoad do I show the webview.
Many times what happens I see the previous data that was loaded to the webview for a brief second before the new data I loaded kicks in.
I already added a delay of 0.2 seconds before showing the webview but it didn't help.
Instead of solving this by adding more time to the delay does anyone know how to solve this issue or maybe clear old data from a webview without release and allocating it every time?
Thanks malaki1974, in my case I wasn't using a modal view.
When I sat with an Apple engineer on WWDC 2010 and asked him this question his answer was simply: "Don't reuse UIWebViews, that's not how they were ment to be used."
Since then I make sure to calls this set of lines before allocating a new UIWebView
[self.myWebView removeFromSuperview];
self.myWebView.delegate = nil;
[self.myWebView stopLoading];
[self.myWebView release];
That solved the issue.
Clear the contents of the webview before you try to load new content
[self loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"about:blank"]]];
First, the UIWebView renders it contents in a background thread. Even when you receive webViewDidFinishLoad: it might not be completely done. Specially if it is an ajax-intense page that comes from the network.
You say you are hiding the view. I wonder if that means that the webview delays its drawing completely. What you could try is to move the UIWebView offscreen or obscure it with another view. Maybe that will change it's drawing behaviour.
If you do not need an interactive UIWebView then you can also consider to do it completely offscreen in a separate UIWindow and then create an image from that UIWebView's layer.
That's what I do, and it works:
[_webView stringByEvaluatingJavaScriptFromString:#"document.open();document.close();"];
Try loading a local file that is blank or has a loading graphic when you hide it, rather than just loading new content when you show it. Since the file is local it will be quick and even if the new page takes a while to load it will have either blank or loading expected behavior.
If you got controll over the html. You can communicate back to objective-c when the document is ready. Like so in jQuery:
function messageNative (name, string) {
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", "appscheme://" + name + "/" + string);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
$(function() {
messageNative('webview', 'ready');
});
And then in UIWebView's delegate method webView:shouldStartLoadWithRequest:navigationType: wait for the request with url equal to "appscheme://webview/ready". Then you should know: the document is loaded and ready for display. Then all that is missing is a simple fade-in or something like that :)

Clickable links in UITableView that open up Safari

I am working on an iPhone app, and would like to be able to click on a link that is in UITableView. When the Link, and only the link is selected I want the Safari app to be opened to the selected link. Any suggestions on how to do this? Thanks so much!
There are multiple solutions to your problem.
If the links are the only object in the cell, then you could just make call the didSelectRowAtIndexPath:(NSIndexPath *)indexPath function of UITableView to gather the link from your array of table data, and then use
[[UIApplication sharedApplication] openURL:myURL];
to open the URL.
Alternatively you could create your own UITableCell subclass that contains a custom button (instead of a rounded rect button) that has no image or background (only text) so that it has the appearance of a link (you could even color the text blue, and underline it...). When the user clicks the button, your handler function would then call the same openURL function as above.
The above method works best if you have multiple items in each cell (which is why you would have to create a custom cell...
A naive approach would be to embed a tiny UIWebView into each cell. UIWebView has a delegate that lets you know when a link is clicked which you can implement to launch the Safari or navigate to a new controller hosting a full screen UIWebView.
This approach might be too resource intensive and I haven't tried it myself but if it does work it would offer a lot of flexibility. Would love to know the results if you try it.
To launch a link in safari use:
NSURL *url = [NSURL URLWithString:#"http://stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(#"%#%#", #"Failed to open url:", [url description]);
}
Is the link in its own row in the UITableView? If so, then you can handle it within didSelectRowAtIndexPath when the appropriate row is clicked.