iOS Question WKWebView - PageFinished

tiagovsilva

Member
Licensed User
PageFinished is not firing, but the webview is working properly.

I have this code:
B4X:
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
   
    Dim no As NativeObject = App
    no.RunMethod("setStatusBarHidden:animated:", Array(True, False))
   
    Page1.RootPanel.LoadLayout("webView")
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    NavControl.NavigationBarVisible = False
    WKWebView1 = CreateWKWebView(Page1.RootPanel)
    WKWebView1.LoadURL(url)
   
    Dim wv As NativeObject = WKWebView1
    wv.GetField("scrollView").SetField("bounces", False)
       
    App.RegisterUserNotifications(True, True, True)
    App.RegisterForRemoteNotifications
    CheckForPushMessage
End Sub

Sub CreateWKWebView (pnl As Panel) As View
    Dim conf As NativeObject
    conf = conf.Initialize("WKWebViewConfiguration").RunMethod("new", Null)
    conf.SetField("allowsInlineMediaPlayback", True)
    Dim wk As NativeObject
    Dim p As NativeObject = pnl
    wk = wk.Initialize("WKWebView").RunMethod("alloc", Null)
    wk.RunMethod("initWithFrame:configuration:", Array(p.RunMethod("frame", Null), conf))
    pnl.AddView(wk, 0, 0, pnl.Width, pnl.Height)
    Return wk
End Sub

Sub WKWebView1_PageFinished (Success As Boolean, Url As String)
    If Url.Contains("enc_educacao") And Success And App.Tag==True Then
        'Do something
        Log(Url)
    End If
   
    Dim wv As NativeObject = WKWebView1
    wv.SetField("allowsInlineMediaPlayback", True)
End Sub
Do you know what's wrong?

Thanks in advance!
 

Biswajit

Active Member
Licensed User
As you are creating the wkwebview by code you have to implement the page finished event by yourself.
 

Biswajit

Active Member
Licensed User
Just create the webview from designer and use this code,

B4X:
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
  
    Dim no As NativeObject = App
    no.RunMethod("setStatusBarHidden:animated:", Array(True, False))
  
    Page1.RootPanel.LoadLayout("webView")
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    NavControl.NavigationBarVisible = False
    'WKWebView1 = CreateWKWebView(Page1.RootPanel) 'add this from designer
    
  
    Dim wv As NativeObject = WKWebView1
    wv.GetField("scrollView").SetField("bounces", False)
    wv.GetField("configuration").SetField("allowsInlineMediaPlayback",true)
      
    WKWebView1.LoadURL(url)
    App.RegisterUserNotifications(True, True, True)
    App.RegisterForRemoteNotifications
    CheckForPushMessage
End Sub

Sub WKWebView1_PageFinished (Success As Boolean, Url As String)
    If Url.Contains("enc_educacao") And Success And App.Tag==True Then
        'Do something
        Log(Url)
    End If
End Sub
 

tiagovsilva

Member
Licensed User
Just create the webview from designer and use this code,

B4X:
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
 
    Dim no As NativeObject = App
    no.RunMethod("setStatusBarHidden:animated:", Array(True, False))
 
    Page1.RootPanel.LoadLayout("webView")
    Page1.RootPanel.Color = Colors.White
    NavControl.ShowPage(Page1)
    NavControl.NavigationBarVisible = False
    'WKWebView1 = CreateWKWebView(Page1.RootPanel) 'add this from designer
   
 
    Dim wv As NativeObject = WKWebView1
    wv.GetField("scrollView").SetField("bounces", False)
    wv.GetField("configuration").SetField("allowsInlineMediaPlayback",true)
     
    WKWebView1.LoadURL(url)
    App.RegisterUserNotifications(True, True, True)
    App.RegisterForRemoteNotifications
    CheckForPushMessage
End Sub

Sub WKWebView1_PageFinished (Success As Boolean, Url As String)
    If Url.Contains("enc_educacao") And Success And App.Tag==True Then
        'Do something
        Log(Url)
    End If
End Sub
It worked!
Thanks!
 
Top