WKWebView is Blank

I’m trying to add a window to myMacOS application that will displace html content. I have a .xib with a window with a WKWebView. In my NSWindowController subclass implementation I have an IBOutlet WKWebView *myWebView. The outlet is connected to the WKWebView in the .xib

I initialize my subclass of NSWindowController with: self = [super initWithWindowNibName: @“WindowName”];

Then in the windowDidLoad method I initialize the WKWebView with code like this:

WKWebViewConfiguration *webConfiguration = [[WKWebViewConfiguration alloc] init];
[webConfiguration defaultWebpagePreferences];
myWebView = [[WKWebView alloc] initWithFrame: [myWebView frame] configuration: webConfiguration];
[webConfiguration release]; //Yes, I know I could use ARC
[myWebView setUIDelegate: nil];

This looks fine in the debugger and doesn’t log any errors.

Then I can create and load a URLRequest with Apple’s example:

NSURL *appleURL = [NSURL URLWithString: @"https://www.apple.com"];
NSURLRequest *myURLRequest = [NSURLRequest requestWithURL: appleURL];
[myWebView loadRequest: myURLRequest];

In order for this to work I have to check the Network Incoming Connections (Server) box in the target’s App Sandbox. (It would be EXTREMELY helpful if this was mentioned in the Developer Documentation)

OR I can get file URLs and folders from the Application Bundle and load than with: [myWebView loadFileURL: helpFileURL allowingReadAccessToURL: helpBundleURL];

In order for this to work I have to check the Network Outgoing Connections (Server) box in the target’s App Sandbox. (It would be EXTREMELY helpful if this was mentioned in the Developer Documentation)

Then when the window is opened and displayed the WKWebView remains blank.

No errors are logged. XCode logs: “WebContent process (0x150001200) took 1.3841 seconds to launch.” so XCode seems to think that the web content was loaded correctly but the WKWebView remains blank. Trying to force it to display with methods like reload and setNeedsDisplay: YES don't fix it.

How can I get the WKWebView to actually display the content?

It looks like it could be a timing problem. When execution returns after the windowDidLoad method the window is drawn to the screen and the content is rendered. It's taking more than a second to launch the WebContent process and load the content. It looks like the Window is drawn and movedToFront before this is complete so it won't draw the html because it isn't yet created. Does this sound possible? I don't see any way to sleep or delay this until the web content is loaded. Is this possible?

I generally proceed like the following :

In windowDidLoad method, I write only these 3 lines :

NSURL *myURL = [[NSBundle mainBundle] URLForResource:@"help" withExtension:@"html"];
helpContent = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
[self.myWebView loadHTMLString:helpContent
                            baseURL:[url URLByDeletingLastPathComponent]];
WKWebView is Blank
 
 
Q