Skip to content

[webview_flutter_wkwebview] add functions to display a system popup using Javascript in iOS #4538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,62 @@ - (void)webView:(WKWebView *)webView
decisionHandler(decision);
}];
}

- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
completionHandler();
}]];
[[self topViewController] presentViewController:alert animated:YES completion:NULL];
}

- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
completionHandler(YES);
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
completionHandler(NO);
}]];
[[self topViewController] presentViewController:alert animated:YES completion:NULL];
completionHandler(true);
}

-(UIViewController *)topViewController{
UIViewController *controller = [self topViewControllerWithRootViewController:[self getCurrentWindow].rootViewController];
return controller;
}

/**
* topViewControllerWithRootViewController
*/
-(UIViewController *)topViewControllerWithRootViewController:(UIViewController *)viewController{
if (viewController==nil) return nil;
if (viewController.presentedViewController!=nil) {
return [self topViewControllerWithRootViewController:viewController.presentedViewController];
} else if ([viewController isKindOfClass:[UITabBarController class]]){
return [self topViewControllerWithRootViewController:[(UITabBarController *)viewController selectedViewController]];
} else if ([viewController isKindOfClass:[UINavigationController class]]){
return [self topViewControllerWithRootViewController:[(UINavigationController *)viewController visibleViewController]];
} else {
return viewController;
}
}
/**
* getCurrentWindow
*/
-(UIWindow *)getCurrentWindow{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if (window.windowLevel!=UIWindowLevelNormal) {
for (UIWindow *wid in [UIApplication sharedApplication].windows) {
if (window.windowLevel==UIWindowLevelNormal) {
window = wid;
break;
}
}
}
return window;
}
@end

@interface FWFUIDelegateHostApiImpl ()
Expand Down Expand Up @@ -164,4 +220,6 @@ - (void)createWithIdentifier:(nonnull NSNumber *)identifier
instanceManager:self.instanceManager];
[self.instanceManager addDartCreatedInstance:uIDelegate withIdentifier:identifier.longValue];
}


@end