My iframe does not work with a UIWebView

后端 未结 1 1818
孤街浪徒
孤街浪徒 2021-01-28 16:29

I have tested my iframe everywhere and it works very well, but on iOS in Objective-C, it does not work on UIWebView, here is

相关标签:
1条回答
  • 2021-01-28 17:25

    You need to add this Key to your info.plist

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
    

    The main problem that I found is the base Url, was missing in your code, so add this code with base url @"http://www.dailymotion.com", and changed the way to load html from loadHTMLString to loadData this always have better results for me

    Edited: Improved your code to handle width of WebView as @Mozahler suggest was wrong

    self.webView.scrollView.scrollEnabled = NO;
    
    NSString *identifierTest = @"x5b4cfz";
    
    NSString *Str = [NSString stringWithFormat:@"<iframe frameborder=\"0\" width=\"%@\" height=\"200\" src=\"//www.dailymotion.com/embed/video/%@\" allowfullscreen></iframe>",[NSString stringWithFormat:@"%f",self.webView.frame.size.width - 10], identifierTest];
    
    NSLog([NSString stringWithFormat:@"%f",self.webView.frame.size.width - 10]);
    
    [_webView loadData:[Str dataUsingEncoding:NSUTF8StringEncoding]
              MIMEType:@"text/html" textEncodingName:@"UTF-8"
               baseURL:[[NSURL alloc] initWithString:@"http://www.dailymotion.com"]];
    

    it works, as you can see

    Hope this helps

    0 讨论(0)
提交回复
热议问题