gpt4 book ai didi

iphone - 为什么我的 nsurl 请求没有出现在控制台中?

转载 作者:行者123 更新时间:2023-11-29 11:02:08 25 4
gpt4 key购买 nike

我正在尝试让重定向的 url 显示在控制台中。我的代码中某处可能遗漏了一个小细节。我们将不胜感激任何帮助。

- (void)viewDidLoad {
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 119, self.view.bounds.size.width, self.view.bounds.size.height - 165)];
webView.backgroundColor = [UIColor whiteColor];
// webView.userInteractionEnabled = NO;
webView.opaque = NO;
[webView loadHTMLString:self.item.description baseURL:[NSURL URLWithString:self.item.link]];
[self.view addSubview:webView];
webView.delegate = self;
}


- (NSURLRequest *)connection:(NSURLConnection *)connection
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)redirectResponse
{
//Make sure tinyurl is doing the redirection
if([[[redirectResponse URL] host] compare:@"bitly.com"
options:NSCaseInsensitiveSearch] == NSOrderedSame)
{
NSLog(@"Redirect Location: %@", [request URL]);
}

//call [connection cancel]; to cancel the redirect and stop receiving data
//return nil; to cancel redirect but continue receiving data
//return request; will continue the redirection as normal
return request;
}

最佳答案

您正在使用 NSURLConnectionDelegate 的委托(delegate)方法这不是 UIWebView

的正确方法

您没有在 UIWebView 中加载任何请求,您希望 NSLog 如何打印出请求?如果您使用 UIWebViewDelegate ,那么检查您的情况的正确方法应该是:

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

NSLog(@"Redirect Location: %@",[request.URL absoluteString]);
}

关于iphone - 为什么我的 nsurl 请求没有出现在控制台中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15365945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com