Creating a WebView using Kotlin and Storyboard

Hi There,

I’m having trouble to create a web view screen on a Kotlin moe project.
I followed the outdated tutorial: https://software.intel.com/en-us/node/633259
but without success.
Could you please tell how to create a Webview using storyboard (with proper outlet settings) then how to set an url from android studio.

Thanks!

Hi!

After created moe “Kotlin > Single View Application”, please following steps:

  • Add the following code in the AppViewController.kt :
override fun viewDidLoad() {
        super.viewDidLoad()

        val urlString = "http://sourcefreeze.com"
        val url = NSURL.URLWithString(urlString)
        val nsurlRequest = NSURLRequest.requestWithURL(url)
        webView().loadRequest(nsurlRequest)
 }

    @Selector("webView")
    @Property
    @IBOutlet
    external fun webView(): UIWebView
  • Add App Transport Security settings to info.plist :
NSAppTransportSecurity

	NSAllowsArbitraryLoads
	

  • Select “Multi-OS Engine Action -> Generate Actions and Outlets for Interface Builder”

  • Select “Multi-OS Engine Actions - > Open Project in Xcode”

  • Drag and Drop ‘UIWebView’ into ‘UIViewController’, and add missed constraints.

  • Open up “moe-main-interfaces.m” in the Assistant Editor and connect WebView into IBOutlet :

@property (strong) IBOutlet UIWebView* webView;
  • Close Xcode project

  • Build and run the application. You should see the content at our requested http://sourcefreeze.com loaded into the UIWebView.

Best Regards,
Roland

1 Like

Hi!

Full sample project:
KotlinWebView.zip (67.1 KB)

1 Like

Thanks a ton Vighr!!
I will give it a try

You guys are doing a great job!! :smile:

Nas

Thanks, It works like a charm!
:+1:

@vighr, Thanks for the previous sample. Do you have an another example/sample using the new WKWebView?

Ok, I found how to do it without the need of using the story board.
If you want to use the WKWebView in fullscreen, just use this very simple method into your viewDidLoad:

 private fun openWkWebView() {
    val webView = WKWebView.alloc()
    webView.init()

    webView.setUIDelegate(object : WKUIDelegate {})// if you want more control over the UIDelegate, just override methods
    webView.setNavigationDelegate(object : WKNavigationDelegate {})// if you want more control over the NavigationDelegate, just override methods
    setView(webView)
    val urlString = "https://threejs.org/examples/#webgl_loader_mmd"
    // val urlString = "https://threejs.org/examples/#webgl_buffergeometry_instancing_billboards"
    // val urlString = "https://threejs.org/examples/#webgl_lines_fat_wireframe"
    val url = NSURL.URLWithString(urlString)
    val nsurlRequest = NSURLRequest.requestWithURL(url)
    webView.loadRequest(nsurlRequest)
    webView.setAllowsBackForwardNavigationGestures(true)
    webView.scrollView().setBounces(false)
    webView.scrollView().setContentInsetAdjustmentBehavior(UIScrollViewContentInsetAdjustmentBehavior.Never) //remove safearea !!!
    }

I am quite impressed with the performance of webGL examples (https://threejs.org/) on physical devices. I am sure anyone can create great apps & games quickly out these technologies :sunglasses:

Here are some screenshots taken from an iPhone 6S+ (60fps)
IMG_0656 IMG_0657 IMG_0658 IMG_0659.PNG