我有一个uiwebview,我打开http://google.com。然后我在谷歌搜索栏中键入内容并搜索某些内容。我想获得由于我在谷歌搜索而生成的更新网址。
- (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];
}
答案 0 :(得分:2)
试试这个
NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"];
希望它对您有用
答案 1 :(得分:1)
以下是一个正确的答案,但它并不适用于Facebook和youtube
NSSTRing * currentURL = webView.request.URL.absoluteString;
如果有人知道更好的答案,请分享。
答案 2 :(得分:0)
- (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];
}
答案 3 :(得分:0)
尝试这种委托方法:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
您可以获取请求的请求和nslog。