iOS Question B4i webview override_URL 'return true' error?

Discussion in 'iOS Questions' started by Albi, Apr 16, 2015.

  1. Albi

    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.
     

    Attached Files:

  2. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Hi
    If you return True then prevent open link.
     
  3. Albi

    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.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Check the value of url before you return true. You are probably preventing it from loading the first one.
     
  5. Albi

    Albi Active Member Licensed User

    i think you're right but i'm not sure what's going on!

    this is the code
    Code:
    '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 StringAs 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: Apr 16, 2015
  6. Erel

    Erel Administrator Staff Member Licensed User

    What is the output of Log(Url)?

    If you like you can upload your project (File - Export as zip) and I'll try it.
     
  7. Albi

    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
    Code:
    Sub WebView1_OverrideUrl (Url As StringAs 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
    Code:
    firstTime=True
    which seems to work ok, but i'm not sure if it's great to do that.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Use this code:
    Code:
    Sub WebView1_OverrideUrl (Url As StringAs Boolean
       
    If Url.StartsWith("file://"Then Return False
       App.OpenURL(Url)
    End Sub
     
  9. Albi

    Albi Active Member Licensed User

    thanks, I shall do!
     
  10. Albi

    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?
     
  11. Albi

    Albi Active Member Licensed User

    i changed it to this which seems to work....
    Code:
    Sub WebView1_OverrideUrl (Url As StringAs Boolean
       
    If Url.StartsWith("file://"Then Return False
       App.OpenURL(Url)
       
    Return True
    End Sub
    Thanks for your help!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice