How to customise the string value in uiweb view ios - iphone

In my application I want to show the URL link value as "Click here to see the link" in UIWebView?
For ex: link: http://www.youtube.com/watch?v=pii4G8FkCA4
I want to show it as in UIWebView as "click here to see the link"
Can any one please help me to how to do that?

Try this,
NSString *html = #"click here to see the link";
[webview loadHTMLString:html baseURL:nil];
This will help you to load URL in webView.

try like this ,you will get,
UIWebView *webview=[[UIWebView alloc]init];
webview.frame=CGRectMake(0, 0, 320, 480);
NSString *html = #"click here to see the link";
[webview loadHTMLString:html baseURL:nil];
[self.view addSubview:webview];

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
[[UIApplication sharedApplication] openURL:[inRequest URL]];
return NO;
}
return YES;
}

TRy this,
viewcontroller.h
IBOutlet UIWebView *webView;
viewController.m
NSString *strHtml = #"click here to see the link";
[webview loadHTMLString:strHtml baseURL:nil];

Related

How to Download a video using UIWebView

I want to download a the video using web-view but I am not getting how to download it?
my video link is here
the sample code for playing video which I am using is
-(void)embedYouTubeInWebView:(NSString*)url theWebView:(UIWebView *)aWebView {
   NSString* html = [NSString stringWithFormat:#"%#", url];
   [aWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:html]]];
}
- (void)viewDidLoad
{
   [super viewDidLoad];
   
  [self embedYouTubeInWebView:#"http://player.vimeo.com/video/32983838" theWebView:myWebView];
   // Do any additional setup after loading the view, typically from a nib.
}
can anyone please help me to download this video?
To download a file i used the following Code. Hope it will work for you too.
- (IBAction)getFileFromFtpServer:(UIView *)sender
{
NSString *stringURL = #"http://player.vimeo.com/video/32983838";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"filename.mpeg4"];
[urlData writeToFile:filePath atomically:YES];
}
}
Try this here your video is playing..
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 380)];
webView.delegate=self;
[webView setOpaque:NO];
webView.backgroundColor=[UIColor clearColor];
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat width = CGRectGetWidth(screen);
CGFloat height = CGRectGetHeight(screen);
UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.frame=CGRectMake((width/2) - 10,(height/2) - 54, 20, 20);
activityIndicator.center=self.view.center;
[activityIndicator hidesWhenStopped];
[self playVideo];
}
-(void) playVideo
{
NSURL *url = [NSURL URLWithString:#"http://player.vimeo.com/video/32983838"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
[activityIndicator startAnimating];
[webView addSubview:activityIndicator];
}
/* WebViewDidStartLoad */
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[activityIndicator startAnimating];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
/* WebViewDidFinishLoad */
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[activityIndicator stopAnimating];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
/* WebViewdidFailLoadWithError */
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
If I understand correctly and in response to above, google has shut down several "converter sites" due to copyright infringements: http://www.real.com/resources/youtube-to-mp3-converter There are other sites available to download video content from (again, assuming you're abiding by the copyright guidelines) : This lists five sites where you can find and download online videos free. To make sure a video is legal to download, look for licensing information about the video. Typically, videos with a “Creative Commons” license are legal to download, but may have limitations on how you use the video. http://www.real.com/resources/download-one-video

Changing tel: property working in simulator but Not in Device

I have changed tel property to do some string manipulation instead of calling that number.
its working in simulator but when i do it device, its still trying to call.
i have tried with webview, textview, button still same problem :(
Any idea?
Let me rephrase
By default, when clicked on any link with tel:xxxx iPhone calls number xxxx
But i don't want calling, instead i want to grab xxxx and append that value to my String.
How to do that.
Thanks
- (void)viewDidLoad {
[super viewDidLoad];
self.htmlString = [self createHTML];
[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];
[webView loadHTMLString:self.htmlString baseURL:nil];
}
- (NSMutableString *) createHTML {
NSMutableString *tempString =[NSMutableString stringWithFormat:#"<div>"];
[tempString appendString:#"John Smith"];
[tempString appendFormat:#"<br> <a href='tel:201207415'>201207415</a>"];
[tempString appendString:#"</div>"];
return tempString;
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
//CAPTURE USER LINK-CLICK.
NSURL *url = [request URL];
NSString *mytext = [url absoluteString];
NSLog(#"%#",mytext);
myLabel.text = mytext;
return YES;
}
If you do not want to call:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
return NO;
}
Simulator cannot call anyway.

XCode: How can I check the URL type on every page load in UIWebView?

I need some sample code to check if the page is 'file', 'http' or 'www' on the page load. At the moment the code is as follows;
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
//CAPTURE USER LINK-CLICK.
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSURL *URL = [request URL];
if ([[URL scheme] isEqualToString:#"file"]) {
[webView loadRequest:request];
[homebutton setHidden:YES];
NSLog(#"Opened File");
return NO;
}
else if ([[URL scheme] isEqualToString:#"http"]) {
[webView loadRequest:request];
[homebutton setHidden:NO];
NSLog(#"Opened External Page");
return NO;
}
else if ([[URL scheme] isEqualToString:#"www"]) {
[webView loadRequest:request];
[homebutton setHidden:NO];
NSLog(#"Opened External Page");
return NO;
}
}
return YES;
}
I want it based around this but this is only when a link is clicked and I want it to apply when a form is filled out and then the form redirects to another page etc...
I would really appreciate a quick answer,
Thank you very much,
James Anderson
Probably you need to check out the various UIWebViewNavigationType listed in the "constants" section here

iphone - start an application at the end of a phone call

Is it possible to launch an application at the end of phone call or after sending SMS?
NO this is not at all possible. Because you cant get the event when the call is ended or message is sent. So theres no way you can open up the application.
Happy Coding...
I got this code from Apple site and it works perfectly:
- (IBAction) dialNumber:(id)sender{
NSString *aPhoneNo = [#"tel://" stringByAppendingString:[itsPhoneNoArray objectAtIndex:[sender tag]]] ;
NSURL *url= [NSURL URLWithString:aPhoneNo];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion floatValue] >= 3.1) {
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
webview.hidden = YES;
// Assume we are in a view controller and have access to self.view
[self.view addSubview:webview];
[webview release];
}
else {
// On 3.0 and below, dial as usual
[[UIApplication sharedApplication] openURL: url];
}
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:aPhoneNo]];
}
Looks like it might help ..
iPhone SDK: Launching an app after call ends

Iphone secondary xib, UIWebview local htm file will not load. I have tried numerous methods nothing has worked

I am loading as secondary view with its own xib file. I can load it fine, but cannot get the webview in it to load any content. I have another app where this proces works, but it is in the main view.
Here is the code I am using.
#synthesize webView;
- (void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"workshop" ofType:#"htm" inDirectory:#"dirA"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData:
[readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
// to make html content transparent to its parent view -
// 1) set the webview's backgroundColor property to [UIColor clearColor]
// 2) use the content in the html: <body style="background-color: transparent">
// 3) opaque property set to NO
//
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
[self.webView loadHTMLString:htmlString baseURL:nil];
[htmlString release];
}
- (void)dealloc
{
[webView release];
[super dealloc];
}
-(IBAction)switchCanary {
[self dismissModalViewControllerAnimated:YES];
}
-(IBAction)switchBack {
[self dismissModalViewControllerAnimated:YES];
}
#end
I figured it out. For some reason I was able to load .htm files before. I had to change them all to .html and now it works. Maybe a recent change. The other app was a couple SDK versions ago.