Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private WebView1 As WebView
Private WebViewDelegate As NativeObject
End Sub
Public Sub Initialize
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
WebViewDelegate = WebViewDelegate.Initialize("MyUIDelegate").RunMethod("new", Null)
WebView1.As(NativeObject).SetField("UIDelegate", WebViewDelegate)
WebView1.LoadUrl("https://www.b4x.com/maps.html")
End Sub
Private Sub WebView1_Confirm (Message As String, url As String)
Msgbox2("Msg", url & " asking: " & CRLF & Message, "", Array ("Yes", "Cancel"))
Wait For Msg_Click (ButtonText As String)
WebViewDelegate.RunMethod("confirm:", Array(ButtonText = "Yes"))
End Sub
#if OBJC
@end
@interface MyUIDelegate :NSObject<WKUIDelegate>
@property (nonatomic, copy) void (^handler)(BOOL result);
@end
@implementation MyUIDelegate {
}
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler {
NSLog(@"test runJavaScriptAlertPanelWithMessage");
completionHandler();
}
- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler {
NSLog(@"test runJavaScriptConfirmPanelWithMessage");
self.handler = completionHandler;
[B4IObjectWrapper raiseUIEvent:webView :@"_confirm::" :@[message, webView.URL.absoluteString]];
}
- (void) confirm:(BOOL)result {
self.handler(result);
self.handler = nil;
}
#End If