Skip to content

Commit 5efc73f

Browse files
feat(ad-hoc): only open universal links if app available (#512)
1 parent b06be3e commit 5efc73f

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Sources/ProcessOutUI/Sources/Modules/NativeAlternativePayment/Interactor/NativeAlternativePaymentDefaultInteractor.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ final class NativeAlternativePaymentDefaultInteractor:
142142
let didOpenUrl: Bool
143143
switch currentState.redirect.type {
144144
case .deepLink:
145-
didOpenUrl = await UIApplication.shared.open(currentState.redirect.url)
145+
didOpenUrl = await openDeepLink(url: currentState.redirect.url)
146146
case .web:
147147
let authenticationRequest = POAlternativePaymentAuthenticationRequest(
148148
url: currentState.redirect.url,
@@ -236,7 +236,7 @@ final class NativeAlternativePaymentDefaultInteractor:
236236
let didOpenUrl: Bool
237237
switch redirect.type {
238238
case .deepLink:
239-
didOpenUrl = await UIApplication.shared.open(redirect.url)
239+
didOpenUrl = await openDeepLink(url: redirect.url)
240240
case .web:
241241
let authenticationRequest = POAlternativePaymentAuthenticationRequest(
242242
url: redirect.url,
@@ -902,6 +902,18 @@ final class NativeAlternativePaymentDefaultInteractor:
902902
)
903903
return nil
904904
}
905+
906+
// MARK: - Redirect Utils
907+
908+
private func openDeepLink(url: URL) async -> Bool {
909+
let options: [UIApplication.OpenExternalURLOptionsKey: Any]
910+
if url.scheme == "https" || url.scheme == "http" { // Determines whether link could be universal
911+
options = [.universalLinksOnly: true]
912+
} else {
913+
options = [:]
914+
}
915+
return await UIApplication.shared.open(url, options: options)
916+
}
905917
}
906918

907919
// swiftlint:enable file_length type_body_length

0 commit comments

Comments
 (0)