Как показать изображения из HTML URL в Webview Swift 4 - PullRequest
0 голосов
/ 13 мая 2019

В одном из моих ответов на веб-сервис я получил html-строку, которая также содержит html-URL изображений. Я должен показать эту строку HTML в веб-просмотре с этими изображениями. Но то, что помешало всему html-коду, отображается правильно, а вместо изображений отображаются поля.

Ниже приведена HTML-строка, которую я получил:

"<div dir=\"ltr\"><div dir=\"ltr\">Your invoice Rs.30<br clear=\"all\"><div><div dir=\"ltr\" class=\"gmail_signature\"><div dir=\"ltr\"><table width=\"600\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"color:rgb(0,0,0);font-family:&quot;Times New Roman&quot;;font-size:medium;width:600px\"><tbody><tr><td colspan=\"3\" style=\"font-family:Arial;margin-bottom:10px;font-stretch:normal;font-size:12px;line-height:normal;color:rgb(34,34,34);padding:0px 0px 10px\">Best Regards,<br><br><table width=\"600\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"color:rgb(0,0,0);font-family:&quot;Times New Roman&quot;;font-size:medium;width:600px\"><tbody><tr valign=\"top\"><td style=\"width:120px;padding-right:10px\"><a href=\"http://eluminoustechnologies.com/\" style=\"color:rgb(17,85,204);display:inline-block\" target=\"_blank\"><img src=\"http://eluminoustechnologies.com/signature/anniversary-signature.png\" alt=\"eluminous logo\" width=\"120\" height=\"\"></a></td><td width=\"500\" style=\"font-family:Arial;display:inline-block;text-align:initial;font-stretch:normal;font-size:12px;line-height:normal;color:rgb(100,100,100);padding:0px 10px;border-left:2px solid rgb(222,222,222)\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tbody><tr><td style=\"font-family:Arial;display:inline-block;text-align:initial;font-stretch:normal;font-size:18px;line-height:normal;color:rgb(34,34,34)\"><b>Sonali Vispute</b><br><span style=\"display:block;color:rgb(100,100,100);font-size:15px;padding-bottom:10px\">Software Engineer</span></td></tr></tbody></table><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tbody><tr><td style=\"font-stretch:normal;line-height:normal;padding:5px 0px\"><span style=\"color:rgb(239,135,32);font-family:Arial;display:inline-block;padding:0px 5px 0px 0px\"><strong>Skype</strong>:</span><font color=\"#222222\" face=\"Arial\">eluminous.se36</font></td></tr><tr><td style=\"padding-top:5px\"><a href=\"https://www.facebook.com/eluminoustech\" style=\"color:rgb(17,85,204)\" target=\"_blank\"><img src=\"http://eluminoustechnologies.com/signature/facebook.png\" width=\"21\" height=\"21\" style=\"border-radius: 0px; border: 0px; width: 21px; height: 21px; display: block; float: left; margin-right: 6px;\"></a>  <a href=\"http://www.linkedin.com/company/eluminous-technologies\" style=\"color:rgb(17,85,204)\" target=\"_blank\"><img src=\"http://eluminoustechnologies.com/signature/linkedin.png\" width=\"21\" height=\"21\" style=\"border-radius: 0px; border: 0px; width: 21px; height: 21px; display: block; float: left; margin-right: 6px;\"></a>  <a href=\"https://twitter.com/eluminoustech\" style=\"color:rgb(17,85,204)\" target=\"_blank\"><img src=\"http://eluminoustechnologies.com/signature/twitter.png\" width=\"21\" height=\"21\" style=\"border-radius: 0px; border: 0px; width: 21px; height: 21px; display: block; float: left; margin-right: 6px;\"></a>  <a href=\"https://plus.google.com/u/0/b/102274258265995536485/+eLuminousTechnologiesPvtLtdNashik/posts\" style=\"color:rgb(17,85,204)\" target=\"_blank\"><img src=\"http://eluminoustechnologies.com/signature/googleplus.png\" width=\"21\" height=\"21\" style=\"border-radius: 0px; border: 0px; width: 21px; height: 21px; display: block; float: left; margin-right: 6px;\"></a> </td></tr><tr><td style=\"padding-top:8px\"><p style=\"color:rgb(239,135,32);margin:0px\"><span style=\"font-family:Arial\">16 years of trust, commitment and co-operation</span><br></p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr></tr></tbody></table></div></div></div></div></div>\r\n"

Ответы [ 2 ]

1 голос
/ 13 мая 2019

Изображения не загружаются из-за безопасности транспорта. .

Просто щелкните правой кнопкой мыши на файле info.plist . Выберите Открыть как -> Исходный код

Добавьте следующие строки в ваш файл info.plist

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

Удалите приложение в симуляторе / iPhone и установите его снова.Ваши изображения из html теперь загружены в webview

Я загрузил html с изображением, используя ваши html данные.Проверьте следующие ss:

enter image description here

и, наконец, добавьте следующую строку в viewDidLoad

webView.loadHTMLString ("htmlString", baseURL: nil)

0 голосов
/ 13 мая 2019

Просто загрузите UIWebView с HTML-строкой

webView.loadHTMLString("htmlString", baseURL: nil)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...