Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cfurlin

Suspended
Original poster
Jun 14, 2011
396
770
I have an app that has a browser window attached to it. The following code was working:

Code:
        let webAddy = URL(string: "https://www.google.com/")
        let myRequest = URLRequest(url: webAddy!)
        myWebView.load(myRequest)

I opened a project using it this yesterday, and it builds correctly but does not load the page. The same code works fine if used in an iOS app, but not macOS.

This code was working a month ago with no issues in macOS. I can't find any references to changes in the Xcode, Swift, or WebKit release notes.

Does anyone know why this is no longer working?
 
I just tested it in a Playground with both AppKit and UIKit, and aside from changing the base view between NSView and UIView, everything worked fine - What Xcode and macOS are you running? Have you tried compiling and running as a .app to see if it's maybe just a bug from within Xcode?
 
I'm using Xcode 11.5 and macOS 10.15.4.

I wound up getting it to work by turning off 'App Sandbox' in the entitlements file.
 
Mac Xcode projects initially turn on the App Sandbox. The sandbox is set up to deny all incoming and outgoing network connections. That means if you use WKWebView in your app, nothing will appear in it until you modify the sandbox settings.

There are two ways to fix this. The first is to turn off the sandbox, which the OP did. The second way is to select the checkboxes to allow incoming and outgoing network connections in the sandbox.

Hopefully this helps someone in the future who encounters this issue.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.