开发者

How to distinguish between link requests in Objective-C

开发者 https://www.devze.com 2023-03-08 12:26 出处:网络
I have the following method in a UIViewController: - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWe开发者_开发知识库bViewNavigationType)navig

I have the following method in a UIViewController:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWe开发者_开发知识库bViewNavigationType)navigationType.

My webview has two links in the view; I want to be able to distinguish between the two of them so that I know which one the user clicked on.

Does anyone know how to?


You must extract a url string from NSURLRequest:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *requestUrl = [request URL];
    NSString *currentPath = [requestUrl path];
...
}

Then use currentPath to compare with your two URLs. If those URL are unknown you should parse your html file to find them in it. You cannot get access to HTML document structure through UIWebView because it is extremely complicated.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号