how to call two url in one webview in iphone - iphone

i want to call two url in one webview one after the another but how i know i can load one url in webview but to call two url please help me one this how to timeinterval on both the url
this is mu single url if but i have to give here two url the how to give and call them
- (void)viewDidLoad {
[super viewDidLoad];
CheapFlightsAppDelegate* app=(CheapFlightsAppDelegate*)[[UIApplication sharedApplication]delegate];
self.navigationController.navigationBarHidden = true;
NSLog(#"Book: %#",app.selectedOutgoingFlight.FlightKey);
NSLog(#"Book: %#",app.selectedInComingFlight.FlightKey);
NSString *hel = #"http://www.bookryanair.com/SkySales/FRSelect.aspx?AvailabilityInputFRSelectView %24ButtonSubmit=Select%20and%20Continue&AvailabilityInputFRSelectView%24m arket1=";
NSString *hel1 =[NSString stringWithFormat:#"%#&",app.selectedOutgoingFlight.FlightKey];
NSString *hel2 = #"AvailabilityInputFRSelectView%24market2=";
NSString *hel3 = [NSString stringWithFormat:#"%#&",app.selectedInComingFlight.FlightKey];
NSString *hel4 = #"__EVENTARGUMENT=&__EVENTTARGET=";
NSString *urlAddress = [NSString stringWithFormat:#"%#%#%#%#%#",hel,hel1,hel2,hel3,hel4];
[spinner startAnimating];
spinner.hidden = NO;
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
NSLog(#"Book: %#",urlAddress);
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
webView.delegate = self;
}

use this method
NSURLRequest *request=[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:#"http://stackoverflow.com/questions/7670889/how-to-call-two-url-in-one-webview-in-iphone/7670992#7670992"]];
[webView loadRequest:request];
[self performSelector:#selector(loadAnother:) withObject:nil afterDelay:10];
-(IBAction)loadAnother:(id)sender{
NSURLRequest *requests=[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:#"http://stackoverflow.com/questions/7683196/uitableview-with-text-that-is-both-right-aligned-and-indented"]];
[webView loadRequest:requests];
}

Set new url of NSURLRequest and call [webView loadRequest:requestObj]; after any time interval you want again.
NSTimer will help you to call method after some interval.
// after loading first url:
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:#selector(loadNewUrl:) userInfo:nil repeats:NO];
//somewhere in delegate define selector
- (IBAction)loadNewUrl:(NSTimer *)timer
{
NSURL *url = [NSURL URLWithString:#"http://www.apple.com/stevejobs"];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
UPDATED:
Implement in your `` methods to detect when webview finished loading first url:
- (void)webViewDidFinishLoad:(UIWebView *)webView;
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;

In "webViewDidFinishLoad" delegate method get the current URL thats loaded using
currentURL = webView.request.URL.absoluteString;
Then check if it matches with your first URL and if it does, Load the second URL that you need to call. If you want, call this second URL after some time using a timer.

Related

IOS - UIWebview - Get the URL of the link clicked and edit the url

I'm creating an app which has a webview. When user click to a link or a button in the webview, I want to be able to get the new url, and edit the new url.
First I initialize the webview with the following url:
- (void)viewDidLoad
{
NSString *id = #"12212323";
[super viewDidLoad];
NSString *fullURL = [[NSString alloc] initWithFormat:#"www.website.com/index.php?id=%#", id];
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
When I click to a link, for example www.website.com/contact.php
Then I edit the new url with www.website.com/contact.php*?id=12212323*
I need to keep the id parameter in all the urls.
The UIWebViewDelegateProtocol should suit your requirements.
In particular the method - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
this is a code to get the current URL
- (void)viewDidLoad
{
NSString *id = #"12212323";
[super viewDidLoad];
NSString *fullURL = [[NSString alloc] initWithFormat:#"www.website.com/index.php?id=%#", id];
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
NSURL *currentURL = [requestObj URL];
NSLog(#"Current URL is %#", currentURL.absoluteString);
}
but to create a URL bar hidden or not is a lot of code, you can start from this tutorial on YouTube is simple and work very well, is possible give you other idea to make a good job ;)
Web Browser Tutorial
hope this help you

Get updated url from uiwebview

I have a uiwebview I open http://google.com in it. Then I type something in google search bar and search for something. I want to get that updated url that is generated as a result of my search on google.
- (void)viewDidLoad
{
[super viewDidLoad];
[self setUrlAddress:#"http://google.com.pk"];
// Do any additional setup after loading the view from its nib.
NSURL *url = [NSURL URLWithString:self.urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[self.webView setScalesPageToFit:YES];
[self.webView loadRequest:requestObj];
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
[appDelegate showActivityView:self.view];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
[appDelegate hideActivityView];
}
Try this
NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:#"window.location.href"];
Hope it will work for you
Below is a correct answer but its not perfectly working for Facebook and youtube
NSSTRing * currentURL = webView.request.URL.absoluteString;
If anyone knows a better answer, please share.
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlAddress = [NSString stringWithFormat:#"http://www.google.com/pk];
//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];
}
try this delegate method :
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
you can get hold of request and nslog that request .

uiwebview not loading the web page

in my program uiwebview is not loading the url address.when i nslogged the request object is not null.however when i nslog the webview.request it returns null.what may be the reason it is not loading
- (void)viewDidLoad {
[super viewDidLoad];
self.web = [[UIWebView alloc] init];
NSString *urlAddress = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
NSLog(#"%#",requestObj);
[self.web loadRequest:requestObj];
[web setFrame:CGRectMake(0, 0, 320, 370)];
NSLog(#"%# %#",self.web,self.web.request);
}
the nslog results are
<NSURLRequest http://www.google.com>
<UIWebView: 0xbb17ff0; frame = (0 0; 320 370); layer = <CALayer: 0xbb12f20>> (null)
as per suggestions from this site i changed it from IB and made it to code .i made the class confirm to uiwebview delegate..both the webviewdidstart and webview did finish are being called these are the nslog outputs from these methods
webviewdidstart
webView-----><NSMutableURLRequest >
webView-----><NSMutableURLRequest http://www.google.com>
webview did finish
webView-finished----><NSMutableURLRequest http://www.google.com>
webView-finished----><NSMutableURLRequest http://www.google.com>
still nothing is being called and i think both these methods are called twice
This is a working code, test this out in your application and let us know the outcome
in .h file, add UIWebViewDelegate
in .m file's viewDidLoad, add this:
UIWebView *webview=[[UIWebView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,460.0)];
NSURL *url = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webview.delegate = self;
[webview loadRequest:requestObj];
[self.view addSubview:webview];
Now check in the delegates if your page is loading or not:
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(#"page is loading");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(#"finished loading");
}
try like this
CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];
NSString *urlAddress = #"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self addSubview:webView];
[webView release];

website not upload using webview

ihave write the following code
but it does nothing in consloe it shows Unknown scheme, doing nothing
[webview setDeleagte self];
[webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:sourcelinkStr]]];
NSString *strURL = #"https://facebook.com";
NSURL *url = [NSURL URLWithString:strURL];
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:url]];
now ,
we have to define Methods For LoadRequest
thanks..

Insert url in one view and then display it in uiwebview in new view

hay all,
I want to enter url in one view and then want to switch and display it in another view in uiwebView I am trying like this but its not working.
NSString *urlAddress = #"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webViewController.page loadHTMLString:urlAddress baseURL:url];
webViewController *sec=[[webViewController alloc] initWithNibName:#"webView" bundle:nil];
[self presentModalViewController:sec animated:YES];
can anybody help me, I am new to iphone World
Try this out,.....
I havent checked it but it will work
NSString *urlAddress = #"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
webViewController *sec=[[webViewController alloc] initWithNibName:#"webView" bundle:nil];
sec.webview=[[UIWebView alloc]initWithFrame:CGRectMake(0,0,320,480)];
sec.webview.delegate=sec;
[sec.webview loadHTMLString:urlAddress baseURL:url];
[self presentModalViewController:sec animated:YES];