Skip to content

Commit

Permalink
Open link in browser on iOS if opening it in in-app browser fails
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Feb 5, 2024
1 parent eb89fb9 commit 6e586eb
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class IOSLinkHandler(
BrowserType.Default -> {
val canOpenUrl = UIApplication.sharedApplication().canOpenURL(url)
if (canOpenUrl) {
dispatch_async(dispatch_get_main_queue()) {
UIApplication.sharedApplication().openURL(url)
}
openBrowser(url)
} else {
inAppBrowser(url)
}
Expand All @@ -57,10 +55,18 @@ class IOSLinkHandler(
}
}

private fun openBrowser(url: NSURL) {
dispatch_async(dispatch_get_main_queue()) { UIApplication.sharedApplication().openURL(url) }
}

private fun inAppBrowser(url: NSURL) {
val safari = SFSafariViewController(url)
safari.modalPresentationStyle = UIModalPresentationPageSheet
try {
val safari = SFSafariViewController(url)
safari.modalPresentationStyle = UIModalPresentationPageSheet

uiViewControllerProvider().presentViewController(safari, animated = true, completion = null)
uiViewControllerProvider().presentViewController(safari, animated = true, completion = null)
} catch (e: Exception) {
openBrowser(url)
}
}
}

0 comments on commit 6e586eb

Please sign in to comment.