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