【问题标题】:UIWebView in Xamarin.iOS seems to ignore external CSS styles?Xamarin.iOS 中的 UIWebView 似乎忽略了外部 CSS 样式?
【发布时间】:2019-04-01 15:06:13
【问题描述】:

我在WebView 中显示 HTML 内容时遇到了一个令人不安的问题,为了便于阅读,我已将 html 内容简化为:

<!DOCTYPE html>
<html lang="en">
    <head>
		<link href="https://www.paytabs.com/theme/payment_page/css/bootstrap.css" rel="stylesheet" type="text/css">
		<link href="https://www.paytabs.com/theme/payment_page/css/custom-rtl.css?timestamp=1540717040" rel="stylesheet" type="text/css">
	</head>

	<body>

<h1 class="text-primary">text one</h1>
<a href="www.stackoverflow.com" class="text-primary">StackOverflow</a>
<div class="container">
                
                    <div class="header-title"><h3>Xamarin</h3></div>
                
            </div>
	<h3 class="text-success">Success</h3>
	<img src="https://i.stack.imgur.com/PwBYM.jpg?s=328&g=1" alt="image"/>
	<h1 class="mark">Mark</h1>
	
	<div class="payment-wrap">
                    <div>
						<label class="payment_method">
                                <input type="radio" id="creditcard" name="payment_type" value="creditcard">
                                <img src="https://www.paytabs.com/images/img/cards.png" width="75" alt="Credit Card">
                        </label>
                                                                            
					</div>
                                           
                    <div class="form-wrap sadad-hide" style="display:none;">
                        <input class="form-control" placeholder="Enter user" value="" maxlength="12" name="olpalias" id="olpalias" autocomplete="off" type="text">
                    </div>
                    <span class="whats-this sadad-hide" style="display:none;">Don't have account?</span>
                    <!--Sadad Enable-->
                    <div id="pt-sadad-enable-outer">
                        <div id="pt-sadad-enable" class="pt-sadad-enable-wrap pt-arrow">
                        <div class="pt-sadad-enable-inner">
                            <h2>How to activate?</h2>
                            <ul class="pt-sadad-htp">
                                <li class="step1 step-help">
                                    <figure>
                                        <img class="img-help" src="https://www.paytabs.com/images/sadad/p1.png" width="50" height="32">
                                        <figcaption>Activate online</figcaption>
                                    </figure>
                                </li>
                                <li class="step2 step-help">
                                    <figure>				
                                        <img class="img-help" src="https://www.paytabs.com/images/sadad/p2.png" width="48" height="33">
                                        <figcaption>Create sadad account</figcaption>
                                    </figure>		
                                </li>
                                <li class="step3 step-help">
                                    <figure>								
                                        <img class="img-help" src="https://www.paytabs.com/images/sadad/p3.png" width="27" height="33">
                                        <figcaption>Add to your account</figcaption>
                                    </figure>						
                                </li>
                            </ul>
                        
                            <a href="https://www.sadad.com/ar/Personal/Pages/RegisterNow.aspx" class="pt-sadad-btn" target="_blank">learn more</a>
                        </div>
                    </div>
                    </div>
                <!-- End Sadad Enable Note-->

                </div>
	</body>

</html>

在这里我设置了webViewSource

 public MainPage()
        {
            InitializeComponent();
            webView.Source = new HtmlWebViewSource
            {
                Html = Resource1.testHtml //containing the HTML above
            };
        }

以下是 Android 上显示的内容(正常):

iPhone:

我尝试使用WkWebViewRenderer 而不是UIWebView,将其添加到iOS 项目的AssembyInfo.cs 文件中:

[assembly: ExportRenderer(typeof(WebView), typeof(Xamarin.Forms.Platform.iOS.WkWebViewRenderer))] 

但这只是缩小了页面大小:

有什么帮助吗?

【问题讨论】:

    标签: html ios webview xamarin.forms xamarin.ios


    【解决方案1】:

    原因: 从 iOS 9 开始,iOS 将只允许您的应用程序与默认实现最佳实践安全性的服务器通信。必须在 Info.plist 中设置值以启用与不安全服务器的通信。

    解决方案: 在您的info.plist 中添加以下代码以信任您的域。

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
          <key>www.paytabs.com</key>
          <dict>       
           <key>NSExceptionRequiresForwardSecrecy</key>
           <false/>
           <key>NSExceptionAllowsInsecureHTTPLoads</key>
           <true/>
           <key>NSIncludesSubdomains</key>
           <true/>
         </dict>
    </dict>
    

    有关更多详细信息,您可以访问此document

    【讨论】:

    • 谢谢。知道为什么 https 网站与 iOS 的连接不安全吗?
    • 因为如果你使用https,服务需要安装SSL证书。
    • 我认为缺少&lt;/dict&gt; 对吧?还是正确的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 2016-09-30
    • 2016-03-16
    • 2014-02-03
    • 2012-03-11
    • 2013-09-07
    • 2016-08-12
    相关资源
    最近更新 更多