代码之家  ›  专栏  ›  技术社区  ›  jbrennan

NSURL从NSURL连接?

  •  4
  • jbrennan  · 技术社区  · 15 年前

    创造一个 NSURLConnection 我通常这样做:

    NSURL *theURL = [NSURL URLWithString:urlString];
    NSURLRequest *req = [NSURLRequest requestWithURL:theURL];
    NSURLConnection *connection = [NSURLConnection connectionWithRequest:req delegate:self];
    

    但是如何才能在委托方法中获得URL呢?我自己也没能抓住它们(我一次运行了很多连接,所以这会变得有点混乱)。似乎我应该能够从一个连接中获取URL。

    我错过什么了吗?

    1 回复  |  直到 11 年前
        1
  •  9
  •   Cory Kilger    15 年前

    In-connection:didReceiveResponse:您可以获取URL。请注意,这可能与创建连接时使用的URL不同,因为连接可能已被重定向。

    - (void)connection:(NSURLConnection *)connection 
                didReceiveResponse:(NSURLResponse *)response {
        NSURL * url = [response URL]; // The URL
    }