我的iframe不能用于UIWebView [英] My iframe does not work with a UIWebView

查看:803
本文介绍了我的iframe不能用于UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在任何地方都测试过我的 iframe ,它运行得非常好,但是在 iOS > Objective-C ,它不能在 UIWebView 上工作,这里是我的代码,有人可以帮我吗?谢谢

  self.webView.scrollView.scrollEnabled = NO; 

NSString * Str = [NSString stringWithFormat:@< iframe frameborder = \0 \width = \359 \height = \200 \src = \// www.dailymotion.com/embed/video/%@\allowfullscreen>< / iframe>,identifier];

[_webView loadHTMLString:Str baseURL:nil];

我的iframe:

 < iframe frameborder =0width =359height =200src =// www.dailymotion.com/embed/video/x5b4cfzallowfullscreen>< / iframe> 


解决方案

您需要将此密钥添加到您的info.plist

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

我发现的主要问题是基本Url,在您的代码中缺失,因此添加此代码使用基本URL @http://www.dailymotion.com,并更改了从 loadHTMLString to loadData 这对我来说总是有更好的结果

已编辑:改进了代码以处理宽度WebView作为@Mozahler建议错误

  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 / htmltextEncodingName:@UTF-8
aseURL:[[NSURL alloc] initWithString :@ http://www.dailymotion.com]];

有效,如您所见



希望这会有所帮助


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 my code, can someone help me? Thanks

self.webView.scrollView.scrollEnabled = NO;

NSString *Str = [NSString stringWithFormat:@"<iframe frameborder=\"0\" width=\"359\" height=\"200\" src=\"//www.dailymotion.com/embed/video/%@\" allowfullscreen></iframe>", identifier];

[_webView loadHTMLString:Str baseURL:nil];

My iframe :

<iframe frameborder="0" width="359" height="200" src="//www.dailymotion.com/embed/video/x5b4cfz" allowfullscreen></iframe>

解决方案

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

这篇关于我的iframe不能用于UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆