public void RunJavaScriptTextInputPanel(WebKit.WKWebView webView, string prompt, string defaultText, WebKit.WKFrameInfo frame, System.Action <string> completionHandler) { // Create a native UIAlertController with the message var alertController = UIAlertController.Create(null, prompt, UIAlertControllerStyle.Alert); // Add a text field to the alert, set the placeholder text and keep a refernce to the field UITextField alertTextField = null; alertController.AddTextField((textField) => { textField.Placeholder = defaultText; alertTextField = textField; }); // Pass the text to the completion handler when the "OK" button is tapped alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, okAction => { completionHandler(alertTextField.Text); })); // If "Cancel" is tapped, we can just return null alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, cancelAction => { completionHandler(null); })); // Present the alert PresentViewController(alertController, true, null); }
public void RunJavaScriptTextInputPanel(WebKit.WKWebView webView, string prompt, string defaultText, WebKit.WKFrameInfo frame, System.Action <string> completionHandler) { var alertController = UIAlertController.Create(null, prompt, UIAlertControllerStyle.Alert); UITextField alertTextField = null; alertController.AddTextField((textField) => { textField.Placeholder = defaultText; alertTextField = textField; }); alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, okAction => { completionHandler(alertTextField.Text); })); alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, cancelAction => { completionHandler(null); })); UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(alertController, true, null); }
public void RunJavaScriptAlertPanel(WebKit.WKWebView webView, string message, WebKit.WKFrameInfo frame, System.Action completionHandler) { // Create and present a native UIAlertController with the message var alertController = UIAlertController.Create(null, message, UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null)); PresentViewController(alertController, true, null); // Call the completion handler completionHandler(); }