CocoaPods trunk is moving to be read-only. Read more on the blog, there are 12 months to go.
| TestsTested | ✗ |
| LangLanguage | Obj-CObjective C |
| License | MIT |
| ReleasedLast Release | Feb 2015 |
Maintained by Otium.
OTMWebView is a UIWebView subclass that attempts to bring some of missing features of the UIWebView to iOS.
Set up OTMWebView instance
#import <OTMWebView/OTMWebView.h>
OTMWebView *webView = [[OTMWebView alloc]initWithFrame:CGRectZero];
webView.delegate = ....;
webView.userAgent = @"My User Agent String";
OTMWebViewDelegate
#import <OTMWebView/OTMWebView.h>
-(void)webView:(OTMWebView *)webView didReceiveResponse:(NSURLResponse *)response forRequest:(NSURLRequest *)request {
if ([response.MIMEType isEqualToString:@"video/mp4"]) {
[webView stopLoading];
// Do something else...
}
}
-(void)webView:(OTMWebView *)webView documentTitleDidChange:(NSString *)title {
//Do something with new title...
}
-(void)webViewProgressDidStart:(OTMWebView *)webView {
// web view's main frame started loading a document
}
-(void)webViewProgressDidFinish:(OTMWebView *)webView {
// web view's document finished loading, as did all of its subresources
}
-(void)webView:(OTMWebView *)webView progressDidChange:(double)progress {
// Update some sort of progress indicator
}Cocoapods is the recommended way to install OTMWebView. Just add pod 'OTMWebView' to your Podfile.
OTMWebView with NSURLProtocol
Steps
OTMWebView's delegate method: - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
NSURLProtocol's + (id)propertyForKey:(NSString *)key inRequest:(NSURLRequest *)request to tell our NSURLProtocol subclass to handle the request.OTMWebView instanceNSURLProtocol subclass's class method + (BOOL)canInitWithRequest:(NSURLRequest *)request method
NSURLProtocol's + (id)propertyForKey:(NSString *)key inRequest:(NSURLRequest *)request, if it is return NO
NSURLProtocol's + (id)propertyForKey:(NSString *)key inRequest:(NSURLRequest *)request, if it is return YES
mainDocumentURL property of the request to see if it contains the identifier of a OTMWebView instance. If it is return YES
mainDocumentURL property of requests for subresources is set the to web view's main request url. This allows us to identify the OTMWebView instance.Since OTMWebView is able to intercept the web view's main requests and the the requests for its subresources, it can track the download progress for all those resources, enabling it to be able to use a similar algorithm to Webkit's to estimate the loading progress of an entire document.
OTMWebView is available under the MIT license. See the LICENSE file for more info.