0

I'm using this project to get me started with the WebKit framework under OSX.

It loads resources locally, and I've been able to get it to work. However, when I alter awakeFromNib to load from a URL string like http://www.example.com/index.html It doesn't work, the view is blank, even though this is a valid URL.

Original:

- (void)awakeFromNib {
    WebPreferences *prefs = [webView preferences];
    [prefs _setLocalStorageDatabasePath:@"~/Library/WebViewExample/LocalStorage"];

    NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
    NSString *htmlPath = [resourcesPath stringByAppendingString:@"/htdocs/640x480_naked.html"];
    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];

}

Modified for external URL:

- (void)awakeFromNib {
    WebPreferences *prefs = [webView preferences];
    [prefs _setLocalStorageDatabasePath:@"/tmp"];

    NSString *urlText = @"http://www.example.com/index.html";
    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
}

What could be wrong?

hookenz
  • 36,432
  • 45
  • 177
  • 286
  • Might be related to transport security? http://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9 – danh Dec 10 '15 at 01:40
  • @danh - Thanks! it turns out that was it. – hookenz Dec 10 '15 at 02:04

1 Answers1

1

Thanks to the comment and link from @danh. This solved it for me.

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>example.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>
hookenz
  • 36,432
  • 45
  • 177
  • 286