Issue loading a url in WKWebView using Xcode 7 beta3

867 Views Asked by At

I am doing a quick test on WKWebView to evaluate its benefits and drawbacks. But i have found is that i am able to load urls using Xcode 6.4 and iOS 8 but having issues loading the same URL in Xcode 7 beta 3.

This is what i am doing :

- (void)viewDidLoad {
    [super viewDidLoad];

    // First create a WKWebViewConfiguration object so we can add a controller
    // pointing back to this ViewController.
    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc]
                                             init];
    WKUserContentController *controller = [[WKUserContentController alloc]
                                           init];

    // Add a script handler for the "observe" call. This is added to every frame
    // in the document (window.webkit.messageHandlers.NAME).
    [controller addScriptMessageHandler:self name:@"observe"];
    configuration.userContentController = controller;

    // This is the URL to be loaded into the WKWebView.
    NSURL *jsbin = [NSURL URLWithString:k_JSBIN_URL3];

    // Initialize the WKWebView with the current frame and the configuration
    // setup above
    _webView = [[WKWebView alloc] initWithFrame:self.view.frame
                                  configuration:configuration];

    // Load the jsbin URL into the WKWebView and then add it as a sub-view.

    [_webView loadRequest:[NSURLRequest requestWithURL:jsbin]];
    [self.view addSubview:_webView];
}

Is there something wrong i am doing or its just the beta version of Xcode and iOS 9? Thanks,

2

There are 2 best solutions below

1
On

It's broken in xcode 7 (Beta)/Swift 2.0 as far as I can see.

I'm using Beta 5 but had the same problem with some earlier Betas.

Fingers crossed it will be fixed in the next beta. I'm sure it will be in the final release.

Maybe they've intentionally blocked it's use due to some issues with Swift 2.0 that they haven't fixed yet.

0
On

In Xcode 7 and iOS 9 you're going to run into problems when using a URL without a SSL certificate.

Adding a certificate will "solve" this issue.

You could also implement the new SFSafariViewController.

Using a domain with without SSL will result in a blank page at least in iOS 9.0.1.