iOS Question WKWebView JavaScript?

dbalman

Member
Licensed User
Longtime User
I switched from the WebView to the WKWebview. It seems that the stringByEvaluatingJavaScriptFromString method does not exist? Is there a replacement method or a different way to inject JS?

B4X:
Method not found: stringByEvaluatingJavaScriptFromString:, target: <WKWebView: 0x14b0be00; frame = (0 0; 414 667); layer = <CALayer: 0x1467add0>>
 

dbalman

Member
Licensed User
Longtime User
I saw that addition, but I don't understand how it works and cannot find documentation on it or examples of it. Please provide an example explaining how to inject JS using this method.
 
Upvote 0

JanPRO

Well-Known Member
Licensed User
Longtime User
I didn't test it:

B4X:
    aWebView.EvaluateJavaScript("Test","alert('Hello, World!');")

Sub EventName_JSComplete (Success As Boolean, Tag As Object, Result As String)
    Select Tag
        Case "Test"
            If Success Then
                Log("JS finish")
            End If
    End Select
End Sub
 
Upvote 0

dbalman

Member
Licensed User
Longtime User
I didn't test it:

B4X:
    aWebView.EvaluateJavaScript("Test","alert('Hello, World!');")

Sub EventName_JSComplete (Success As Boolean, Tag As Object, Result As String)
    Select Tag
        Case "Test"
            If Success Then
                Log("JS finish")
            End If
    End Select
End Sub

I spoke too soon. EvaluateJavaScript is not a valid member of WKWebView. Any other ideas?
 
Upvote 0

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,
How do I use WKWebView?
You have to add WKWebView via the Designer:

1.) Add a reference to iUI8 in the "Libraries Manager" tab
2.) Add #MinVersion: 8.0 to your project attributes
3.) Go into the Designer, click Add View-->CustomView-->WKWebView
4.) Now you can use WKWebView like a normal WebView

Finish ;)

Jan
 
Last edited:
Upvote 0
Top