I'm having an issue where a video resource in my UIWebView
is not loading. This is only an issue on an actual device- everything works perfectly on the simulator.
Note: I've already checked this and the issue there has to do with loading the same content multiple times. NSURLProtocol isn't asked to load after YES response to canInitWithRequest
The actual page loads fine- in my custom NSURLProtocol
, it returns YES
from canInitWithRequest
(several times) and then startLoading
is called after about the 4th or 5th time. It then loads my css file in a similar fashion. Then I see that the request for my video object returns YES
from canInitWithRequest
, but nothing happens with it. startLoading
is never called for the request of my video resource. Here's the simplified log from my device when I load the page:
canInitWithRequest: https://WebpageURL
canInitWithRequest: https://WebpageURL
canInitWithRequest: https://WebpageURL
canInitWithRequest: https://WebpageURL
canInitWithRequest: https://WebpageURL
START LOADING: https://WebpageURL
canInitWithRequest: https://WebpageURL
canInitWithRequest: https://WebpageURL
canInitWithRequest: https://WebpageURL
canInitWithRequest: https://cssResource
START LOADING: https://cssResource
canInitWithRequest: https://MyVideoResource
When I load the exact same page from the simulator running the same iOS version on the exact same device type, the logs show that the resource actually starts loading here for some reason:
canInitWithRequest: https://WebpageURL
canInitWithRequest: https://WebpageURL
canInitWithRequest: https://WebpageURL
START LOADING: https://WebpageURL
canInitWithRequest: https://WebpageURL
canInitWithRequest: https://cssResource
START LOADING: https://cssResource
canInitWithRequest: https://MyVideoResource
canInitWithRequest: https://MyVideoResource
START LOADING: https://MyVideoResource -- WHY NOT ON DEVICE?
The page is left with a video that never plays- just a white box where it should be and the "Play video" button over it. The page looks like it's constantly loading something (Activity indicator in the status bar is spinning) but nothing is happening, and the network activity in Xcode's Debug navigator is flatlined.
tl;dr
Does anyone know why loading this resource is never attempted on my iPhone? Obviously the simulator knows that it needs to be loaded.
EDIT: Here is the slightly redacted relevant code from my NSURLProtocol
@implementation CHHTTPURLProtocol
{
NSURLConnection *connection;
NSHTTPURLResponse *httpResponse;
NSData *responseData;
}
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
if (/* key exists on request */)
return NO;
else if (/* not http or https */)
return NO;
NSLog(@"canInitWithRequest: %@", request.URL.absoluteString);
return YES;
}
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
{
return request;
}
- (void)startLoading
{
NSMutableURLRequest *request = [self.request mutableCopy];
NSLog(@"START LOADING: %@", request.URL.absoluteString);
if (authenticate) authenticate(request);
/* add key to request */
connection = [NSURLConnection connectionWithRequest:request delegate:self];
}
- (void)stopLoading
{
[connection cancel];
connection = nil;
}
/* Other methods like connection:didReceiveData: and connectionDidFinishLoding: */
+ (void)authenticateWithBlock:(AuthenticationBlock)block
{
authenticate = block;
}
static AuthenticationBlock authenticate;