Reputation: 9098
How would you detect any attempt to display an SSL URL that contains non-SSL assets in WebView? Just like a browser gives you a mixed-SSL warning.
I don't see any obvious property on UIWebView or UIWebViewDelegate. I could subclass NSURLProtocol, and somehow communicate the non-SSL connections back to the UIWebView. Is there an easier way to do this?
Upvotes: 0
Views: 1746
Reputation: 17015
One solution is to create your custom URL cache and make it the default so you can catch all HTTP requests, and then you can check for mixed SSL content.
Here is an example:
@interface MonitoringURLCache : NSURLCache
@end
@implementation MonitoringURLCache
- (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest *)request {
NSURL *requestURL = [request URL];
NSURL *pageURL = [request mainDocumentURL];
if ([[pageURL scheme] isEqualToString:@"https"] && [[requestURL scheme] isEqualToString:@"http"]) {
NSLog(@"Non safe resource: %@ referenced from page: %@", requestURL, pageURL);
}
return [super cachedResponseForRequest:request];
}
@end
/// Register your custom cache
MonitoringURLCache *cache = [[MonitoringURLCache alloc] init];
[NSURLCache setSharedURLCache:cache];
/// Make a request to a website with mixed SSL content
NSURL *url = [NSURL URLWithString:@"https://some-website-with-mixed-ssl-content/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
Upvotes: 1