iOS Question B4i webview override_URL 'return true' error?

Albi

Active Member
Licensed User
Hello,

Using a webview, when I include Return True in the Override_URL sub, the webview doesn't load anything - it just shows a white screen. When I comment it out, the webview works fine except I can't intercept the click which means that the webview in the app also follows the link.

I've attached a simple example. Any help would be much appreciated!
Thanks.
 

Attachments

Albi

Active Member
Licensed User
yes, that is what i am trying. sorry i wasn't clear; when i set it to return true, the webview doesn't appear properly, it's just a white screen.
 

Albi

Active Member
Licensed User
i think you're right but i'm not sure what's going on!

this is the code
B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page

    Private WebView1 As WebView
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page")
    Page1.RootPanel.LoadLayout("main")
    NavControl.ShowPage(Page1)
    WebView1.LoadUrl("file://" & File.Combine(File.DirAssets, "homepage.html"))
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
  
End Sub

Private Sub Application_Background
  
End Sub

Sub WebView1_OverrideUrl (Url As String) As Boolean
    Log(Url)
    App.OpenURL(Url)
    Return True
End Sub
if i put a breakpoint on the loadurl line, the device shows the webview correctly. but i have no idea how to fix this.
edit: when i put a breakpoint anywhere in application_start, if i press f5 the same issue occurs. if i step through, then there is no problem. If i put a breakpoint at end sub, then there is no problem.
the override_url code is running when the app starts, even though nothing i can see should start it running. i am (clearly!) very confused as to what is happening!
 
Last edited:

Albi

Active Member
Licensed User
i attached the project in the first post.
the output of the log is
file:///private/var/mobile/Applications/[bunch of numbers and letters which i'm not sure i should post]/tmp/virtual_assets/homepage.html

last night i changed the override_url sub code to
B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
If firstTime = False Then
    Log(Url)
    App.OpenURL(Url)
    Return True
Else
    firstTime = False
End If
End Sub
and put this in application start
B4X:
firstTime=True
which seems to work ok, but i'm not sure if it's great to do that.
 

Albi

Active Member
Licensed User
When I use that, it opens the link in Safari, however, it also opens it in the WebView in the app?
 

Albi

Active Member
Licensed User
i changed it to this which seems to work....
B4X:
Sub WebView1_OverrideUrl (Url As String) As Boolean
   If Url.StartsWith("file://") Then Return False
   App.OpenURL(Url)
   Return True
End Sub
Thanks for your help!
 
Top