2

I am working on a mac app project.Using WKWebView's loadHTMLString method,I am able to construct a web page view,it works well except for the image loading part.

For example:

NSString *string1 = @"<img src=\"https://apppie.files.wordpress.com/2014/09/photo-sep-14-7-40-59-pm_small1.jpg\">"
[pWebView loadHTMLString: string1 baseURL: nil];

That works well. But once I change https: to http:,the web page is broken, image is not showing anymore. I have checked both urls on Firefox browser,they all go well. I don't understand why this is happening.

And then I try to replace all http: with https:,most of images of the web page load properly, but still not all of them.(Again,I double check it in Firefox,all images show up without problem),so I am pretty sure there is something wrong with WKWebView configuration,how can I fix that?Thanks a lot.

My OSX version: 10.11 public beta 5; xCode version: 7.0 beta.

Community
  • 1
  • 1
Li Fumin
  • 1,383
  • 2
  • 15
  • 31
  • 1
    If you are developing for iOS9, you must read about `NSAppTransportSecurity `. Here is an SO question / answer to get you started. `http://stackoverflow.com/questions/32382541/app-tranport-security-exeptions-ios9` – ICL1901 Sep 09 '15 at 15:38
  • @DavidDelMonte You've saved my day! Your answer point me to the right solution and completely solve my problem. Great answer, thanks a lot. Would you repost this as a formal answer? So I can mark your answer as final solution. :) – Li Fumin Sep 10 '15 at 07:46

1 Answers1

4

If you are developing for iOS9, you must read about NSAppTransportSecurity. Here is an SO question / answer to get you started.

My own info.plist file includes:

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

This is probably much more open than I should be, but I'll change over time to limit access to specific URLs that I need. How to do this is also shown in the linked q/a.

Glad this helped!

Community
  • 1
  • 1
ICL1901
  • 7,632
  • 14
  • 90
  • 138