uWebKit WebView not showing on iOS device

Anyone out there using uWebKit?

I’m trying to implement uWebKit (to display a webpage) in the GUI of my app on iOS.

The example WebGUI scene builds and works fine on my device. Also, in my scene, if I operate in Play Mode using the Unity Remote, the WebView works fine and operates as expected.

However, when I build my scene to my device, the WebView won’t show. I have copy and pasted the example code exactly. I have tried using OnWebGUI within an if / then statement with a flag. I have tried it outside the if / then (but still in the OnGUI function) and used UWKView.Show(bool) to enable and disable. Again, this works if I modify the example scene to this method in play mode and on the device. In my scene it works in play mode as well. But if I build to the device, it doesn’t show.

I am incorporating other textures on the GUI using DrawTexture (they animate in and out of the screen, and work fine), but I don’t see why that would affect it. (Doesn’t affect it in Play Mode. And it’s not somehow hiding behind a texture, since even if I disable them it still won’t show.) I am also using the Vuforia AR plugin, but in a separate scene using AR it still works fine on the device. Also works fine with AR in Play Mode.

I am sure I am doing something incorrectly, but I can’t narrow it down since it only fails on the device. No errors in Unity or Xcode. Any ideas? My code is in JS, since I’m not too comfortable with C#…and I’m not much of a coder, so apologies if it’s sloppy.

Thanks in advance.

#pragma strict

var header : Texture;
var backgroundTexture : Texture;
var GUIEnabled : boolean = false;
var webEnabled : boolean = false;
var imageTargetToControl : GameObject;

private var View : UWKView;
private var X = 0;
private var Y = 0;
private var Transparency = 100.0f;
private var URL = "http://www.google.com"; 
private var screenHeight : int;
private var screenWidth : int;
private var webWidth : int;
private var webHeight : int;
private var headerStartHeight : int;
private var headerEndHeight : int;

private var backgroundLocation : Rect;
private var backgroundOffScreen : Rect;
private var backgroundOnScreen : Rect;

private var headerLocation : Rect;
private var headerOffScreen : Rect;
private var headerOnScreen : Rect;

private var GUImoverate = 0.5f;
var completion = 0.00f;

var animateOut = false;
var animateIn = false;


function Start () {

	screenHeight = Screen.height;
	screenWidth = Screen.width;
	webWidth = Screen.width;
	webHeight = Screen.height-100;
	
	backgroundOffScreen = Rect(0,screenHeight,screenWidth,screenHeight);
	backgroundOnScreen = Rect(0,0,screenWidth,screenHeight);
	backgroundLocation = backgroundOffScreen;
	
	headerStartHeight = screenHeight*2-100;
	
	headerOffScreen = Rect(0,headerStartHeight,screenWidth,100);
	headerOnScreen = Rect(0,webHeight,screenWidth,100);
	headerLocation = headerOffScreen;

		
	//Create WebView
	View = UWKCore.CreateView("BasicWebGUI", URL, webWidth, webHeight);
	Debug.Log(View);

}

function Update () {
	
	//Determine touch		
	for(var curTouch in Input.touches){
		if(curTouch.phase == TouchPhase.Began){	
			//there's been a tap this frame - see if the user tapped us
			var ray = Camera.main.ScreenPointToRay(curTouch.position);
			var hit : RaycastHit;
			if(Physics.Raycast(ray, hit, Mathf.Infinity)) 	//the touch was over our collider - perform the drag
				if(hit.transform == transform)
					Tapped(curTouch);		
		}
	}
	
}


function OnGUI () {

	if (GUIEnabled) {	
			
		//Draw BG texture
		GUI.DrawTexture(backgroundLocation, backgroundTexture, ScaleMode.StretchToFill);
		
		//Draw bottom bar
		GUI.DrawTexture(headerLocation, header, ScaleMode.StretchToFill);
		
		//Close button, and set flags accordingly
		if (GUI.Button (Rect (10,screenHeight-85,150,75), "Close")) {
			if (imageTargetToControl!=null) {imageTargetToControl.SetActiveRecursively(true);}
			animateOut = true;
			animateIn = false;
		}
	
	}
	
	//Draw webview
	View.OnWebGUI(X, Y, webWidth, webHeight);
	View.Show(GUIEnabled);
	
	//Move GUI in or out of screen
		
	if (animateIn) {
		if (completion < 1) { 
			completion += Time.deltaTime * GUImoverate;
		} else { animateIn = false; } 

		backgroundLocation = Rect(backgroundLocation.x, Mathf.SmoothStep(backgroundOffScreen.y, backgroundOnScreen.y, completion), backgroundLocation.width, backgroundLocation.height);
		headerLocation = Rect(headerLocation.x, Mathf.SmoothStep(headerOffScreen.y, headerOnScreen.y, completion), headerLocation.width, headerLocation.height);

	} 
	
	if (animateOut) {
	
		if (completion > 0) { 
			completion -= Time.deltaTime * GUImoverate; 
		} else {
			animateOut = false;
			GUIEnabled = false; 
		}
		
		backgroundLocation = Rect(backgroundLocation.x, Mathf.SmoothStep(backgroundOffScreen.y, backgroundOnScreen.y, completion), backgroundLocation.width, backgroundLocation.height);
		headerLocation = Rect(headerLocation.x, Mathf.SmoothStep(headerOffScreen.y, headerOnScreen.y, completion), headerLocation.width, headerLocation.height);

	}

}

function Tapped(theTouch : Touch)  {

	//Set flags and deactivate image target
	GUIEnabled = true;
	animateIn = true;
	if (imageTargetToControl!=null) {imageTargetToControl.SetActiveRecursively(false);}

}

This is from February, and I’m facing the same issue. Any update on if you were able to resolve this?

Hi Mike-

I never got an official answer, and ended up abandoning this product for the Prime31 Etcetera plugins to show a web view, which limited me in some respects, but also actually gave me controls on the web view. Unfortunately, I have cleared out all my old uWebKit code so this is from memory.

To your problem, the best I could figure is that it somehow gets confused on two things.

  1. Try starting the webview at something besides 0,0. Like 1,1. I think there may be a limit problem in their code and it might not like the zeros in the starting coordinates.

  2. Put in a line to clear out all other webviews. Somewhere in their API there’s some code to kill or remove any created webviews, so I made sure this happened before I created a new one. I believe that helped.

Hope that gets you at least a little farther down the road.