iframeのURLに反応するshouldStartLoadWithRequestに対する対処法
以下のようにメインコンテンツとiframeかを判定することにより、iframeにshouldStartLoadWithRequestが反応しても対処ができます。
Swift
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if request.URL.absoluteString == request.mainDocumentURL?.absoluteString {
// メインコンテンツ(読み込もうとしているWebView)の読込時の処理
}
// iframeのURLの読み込み時の処理
}
Objective-C
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([request.URL.absoluteString isEqualToString:request.mainDocumentURL.absoluteString]) {
// メインコンテンツ(読み込もうとしているWebView)の読込時の処理
}
// iframeのURLの読み込み時の処理
}