LoginSignup
1
2

More than 3 years have passed since last update.

【Swift・Objective-C】iframeを含むWebViewを表示する際にshouldStartLoadWithRequest:が呼ばれてしまう時の対処法

Posted at

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の読み込み時の処理
}

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2