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?