From ef0ae642484e5aa2b3fd5fd0d31c36e01ad73a6f Mon Sep 17 00:00:00 2001 From: Suneet Jain Date: Mon, 2 Sep 2024 17:33:02 +0200 Subject: [PATCH] Update CDVWKInAppBrowser.m --- src/ios/CDVWKInAppBrowser.m | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ios/CDVWKInAppBrowser.m b/src/ios/CDVWKInAppBrowser.m index cee483091..445d52102 100644 --- a/src/ios/CDVWKInAppBrowser.m +++ b/src/ios/CDVWKInAppBrowser.m @@ -303,13 +303,22 @@ - (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options [self.webViewEngine loadRequest:request]; } -- (void)openInSystem:(NSURL*)url +- (void)openInSystem:(NSURL *)url { - [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) { - if (!success) { - [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; - } - }]; + // Check if the URL can be opened + if ([[UIApplication sharedApplication] canOpenURL:url]) { + + // Use the new method to open the URL with completion handler + [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) { + if (!success) { + // Post a notification if the URL could not be opened + [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; + } + }]; + } else { + // Post a notification if the URL can't be opened + [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; + } } - (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command