8

Tried ARKit to show WKWebView and all I got is a page that shows background but no foreground. The page can be scrolled though. I attached Apple web page as screenshot.

Here's the code:

DispatchQueue.main.async {
  let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: 640, height: 480))
  let request = URLRequest(url: URL(string: "https://www.apple.com")!)

  webView.load(request)
  plane.firstMaterial?.diffuse.contents = webView
}

Apple web page in ARKit

Does that mean ARKit cannot display web page? I am using iOS 12 beta 2 running ARKit 2. I have also switch off App Transport Security Settings and allow arbitrary load.

I also look through this site and found someone with the same issue but no solution: WKWebView is showing only background

Update: It works for UIWebView.

Lim Thye Chean
  • 8,704
  • 9
  • 49
  • 88

3 Answers3

0

The documentation explicity states that you can't display UIViews as a SCNMaterialProperty:

SceneKit cannot use a layer that is already being displayed elsewhere (for example, the backing layer of a UIView object).

One workaround would be to create an UIImage of the page and present that.

jlsiewert
  • 3,494
  • 18
  • 41
  • But it works on UIWebView - isn't this a UIView object? – Lim Thye Chean Jul 02 '18 at 13:09
  • I have also gotten it to work sometimes, but not reliable. I would look for an alternative solution. – jlsiewert Jul 03 '18 at 15:17
  • Thanks. UIWebView seems to work reliably for me, but deprecated. – Lim Thye Chean Jul 04 '18 at 00:28
  • 8
    I second that. UIWebView works (with its own subsequent set of issues i.e first responder problems) but is deprecated so there’s no future in using that. WKWebView just does not work. Perhaps there is a way to extract the backing layer perhaps? Come on Apple, if you’re gonna force the deprecation UIWebView, at least let’s get WKWebView working in ARKit. Loads of people want to stick a web page on a wall. – Geoff H Jul 10 '18 at 19:19
0

It would be difficult to implement it using Scenekit Nodes, but would be working if you use SprikeKit Nodes. Use SpriteKit nodes for this.

Mohammed Janish
  • 207
  • 4
  • 17
  • To add to this - if you can get this working in a SpriteKit scene, I believe you can use the SpriteKit scene as the material for a SCNNode. However you would have to capture user interaction and forward it to the WKWebView manually. – Dennis L Oct 03 '18 at 16:19
  • Go on then, how do you add a WKWebView to a SpriteKit scene. I think you’ll find you can’t. Only as a subview of the SKView. Which means you won’t be able to use it as a SpriteKit texture. But I’d love you to prove me wrong. – Geoff H Oct 04 '18 at 13:10
0

It is not supported, unfortunately.

Look here for more info: Apple Developer Forum

Mikkel Cortnum
  • 481
  • 4
  • 11