Home Features Docs Blog Support GitHub

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?