繁体   English   中英

如何获取在UIWebView中加载的页面的http://地址?

[英]How to get http:// address of page loaded in UIWebView?

我拥有webView,并将cookie发送到我的站点以使用相同的会话(网络商店)。

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(self.view.frame), CGRectGetMaxY(self.view.frame))];
[webView setDelegate:self];
[self.view addSubview:webView];

NSString *sessionId = [[OCRESTAPIClient sharedClient] sessionId];
NSString *value = [@"xid=" stringByAppendingString:sessionId];

NSURL *url = [NSURL URLWithString:@"http://MySite.ru/cart"];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:value forHTTPHeaderField:@"Cookie"];

[webView loadRequest:request];

用户可以在我的网站上行走,我必须知道他在哪里。 如何在webView中获取已加载页面的网址?

请使用以下方法使您的班级成为网络视图的代表:

webView.delegate = self

然后重写委托方法,

func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        print("current url is \(request.mainDocumentURL!.absoluteString)")
        return true;
}

这将给当前的URL被加载

使用UIWebView委托方法

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
  self.url = webView.request.mainDocumentURL;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM