Answer the question
In order to leave comments, you need to log in
UIWebView: how to catch page load event on ajax sites?
Good afternoon!
Please tell me how to catch the page loading event on ajax sites when the delegate methods:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
- (void)webViewDidFinishLoad:(UIWebView *)webView
Answer the question
In order to leave comments, you need to log in
If the buttons are always active, is there a problem with navigation? Methods goBack goForward fulfill?
In any case, NSURLProtocol can help. Here's a no-frills example . On the didReceiveResponse event, you can check canGoBack and canGoForward Google a
little on the topic, the guys on stackoverflow.com still have problems with html5 cache on iOS 7.
Hmm ... and when loading this page into the browser using my protocol, in general, the brakes and freezes are considerable. It seems to do everything like here :
@implementation WebBrowserURLProtocol
{
NSURLConnection *_connection;
}
#pragma mark - NSURLProtocol
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
if ([NSURLProtocol propertyForKey:@"urlConnectionSent" inRequest:request] != nil)
return NO;
return YES;
}
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
{
return request;
}
- (void)startLoading
{
NSMutableURLRequest *newRequest = [self.request mutableCopy];
[NSURLProtocol setProperty:@YES forKey:@"urlConnectionSent" inRequest:newRequest];
_connection = [NSURLConnection connectionWithRequest:newRequest delegate:self];
}
- (void)stopLoading
{
[_connection cancel];
}
#pragma mark - NSURLConnectionDelegate
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.client URLProtocol:self didLoadData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[self.client URLProtocol:self didFailWithError:error];
_connection = nil;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageAllowed];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[self.client URLProtocolDidFinishLoading:self];
_connection = nil;
[WebBrowserURLProtocol postNotification];
}
#pragma mark - Notifications
+(void)postNotification
{
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"kURLProtocolDidFinishLoading" object:nil];
});
}
@end
@implementation WebBrowserURLProtocol
+(void)postNotification
{
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"kURLProtocolDidFinishLoading" object:nil];
});
}
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
[WebBrowserURLProtocol postNotification];
return NO;
}
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request
{
return request;
}
- (void)startLoading
{
}
- (void)stopLoading
{
}
@end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question