[英]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.