2

我有一个 uiwebview 我在其中打开http://google.com。然后我在谷歌搜索栏中输入一些东西并搜索一些东西。我想获取由于我在 google 上搜索而生成的更新后的 url。

- (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];
}
4

4 回答 4

2

试试这个

NSString *currentURL = [webView stringByEvaluatingJavaScriptFromString:@"window.location.href"];

希望它对你有用

于 2013-03-01T11:35:55.150 回答
1

以下是正确答案,但它不适用于 Facebook 和 youtube

NSSTRing * currentURL = webView.request.URL.absoluteString;

如果有人知道更好的答案,请分享。

于 2014-01-14T13:36:43.717 回答
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];

}
于 2013-03-01T11:34:16.317 回答
0

试试这个委托方法:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

您可以获取 request 并 nslog 该请求。

于 2013-03-01T12:24:32.293 回答