iOS Question Method not found: stringByEvaluatingJavaScriptFromString

MarkInAZ

Member
Licensed User
Longtime User
Hello,

I am working with B4i and was doing some testing in an app that calls javascript using the method 'stringByEvaluatingJavaScriptFromString'. I am running IOS 14.3 I have compiled this app quite a long time ago under iOS 10-12 with no issue. Not sure if something has changed and I did not catch it.

Error in the attached app:
Error occurred on line: 176 (Main)
Method not found: stringByEvaluatingJavaScriptFromString:, target: <WKWebView: 0x10903e600; frame = (200 60; 160 160); layer = <CALayer: 0x281a91740>>

Line 176:
NaObj.RunMethod("stringByEvaluatingJavaScriptFromString:", Array(Script))

Any insight would be appreciated.

Cheers, Mark
 

Attachments

  • Gauge.zip
    48.4 KB · Views: 222

roumei

Active Member
Licensed User
The method you're calling is deprecated since iOS 13: stringByEvaluatingJavaScriptFromString:

You could try to call WebView.EvaluateJavaScript (with Wait For if needed). See Erel's example: EvaluateJavaScript
The following code runs fine here but I'm not sure what the expected result is. You might have to check 'Success' or do something with 'Tag' or 'Result'.

B4X:
Sub JS (Script As String, WebV As WebView)
    'Dim NaObj As NativeObject = WebV
    'NaObj.RunMethod("stringByEvaluatingJavaScriptFromString:", Array(Script)) ' deprecated
    WebV.EvaluateJavaScript(Script)
    Wait For WebV_JSComplete (Success As Boolean, Tag As Object, Result As String)
End Sub
 
Last edited:
Upvote 0

MarkInAZ

Member
Licensed User
Longtime User
Awesome and Perfect ...Thank you!

I was thrown off because we did not update to iOS13 because of issues we had. We upgraded to iOS 14 from iOS12 and continued to use our gauge apps that were deployed in iOS12. Those apps never threw an error while using them in iOS14. Not until we had to update several gauge apps in iOS14 and redeploy, did we come across the method error.

After adjusting the canvas gauge sizes in the contained JavaScript, all is working perfect!

Cheers, Mark
 
Upvote 0
Top