Question

I have a problem where I load a URL in UIWebView. The URL redirects to a different location. I handle this redirect with the following code:

- (NSURLRequest *)connection:(NSURLConnection *)inConnection willSendRequest:(NSURLRequest *)inRequest redirectResponse:(NSURLResponse *)inResponse {

    if(inResponse) {
        NSMutableURLRequest *req = [[inConnection originalRequest] mutableCopy];
        [req setURL:[inRequest URL]];

        return req;
    }

    return inRequest;
}

However, when the page loads, I get 404 on all the images. I can load the URL in Safari without any problems. This is happening on iOS6.1 and iOS7

I'm completely stumped as to what to do. Unfortunately, I don't have access to the server, so I have to handle everything in my app.

Thanks for any advice.

Was it helpful?

Solution

Ah okay, So what seems to have been happening, is that the my custom auth protocol was handling the initial request, then when the redirect request came in, a second caching protocol was intercepting the request for the images and breaking the redirect.

In the authprotocol, in the startLoading method I do the following:

[NSURLProtocol setProperty:@YES forKey:@"AuthSet" inRequest:newRequest];

So in the caching protocol's canInitWithRequest method I do the following:

if([NSURLProtocol propertyForKey:@"AuthSet" inRequest:request] != nil)
    return NO;

Since, when we are caching, we have no need to follow redirects. So basically if the Auth protocol grabs the request, the caching protocol should not respond to it.

Will update after some testing to see if there are any other side effects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top