From cf58b04097ad53151f4c456d0fef27dd5cecd966 Mon Sep 17 00:00:00 2001 From: Dan Polivy Date: Wed, 22 Aug 2018 14:43:06 -0700 Subject: [PATCH] CB-14234: Don't call handleOpenURL for system URLs (#278) When calling `.open()` with a target of `_system`, the InAppBrowser on iOS is both launching the URL in the system browser AND also broadcasting to open the URL within the app (calling handleOpenURL). The latter behavior is problematic in many circumstances (e.g. when you want to explicitly open a link in a browser which is a universal link handled by the app). This commit attempts to address this by checking the return value from openURL -- if it does not open the URL successfully, then (and only then) the code falls back to broadcasting the event within the app to handleOpenURL. --- src/ios/CDVInAppBrowser.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m index fcd8d984e..0ca3feb15 100644 --- a/src/ios/CDVInAppBrowser.m +++ b/src/ios/CDVInAppBrowser.m @@ -299,8 +299,9 @@ - (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options - (void)openInSystem:(NSURL*)url { - [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; - [[UIApplication sharedApplication] openURL:url]; + if ([[UIApplication sharedApplication] openURL:url] == NO) { + [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; + } } // This is a helper method for the inject{Script|Style}{Code|File} API calls, which