Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEN-3215: Add support for deeplinks from hedvig #1706

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Projects/App/Config/Production/Hedvig.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:hedvig.page.link</string>
<string>applinks:www.hedvig.com</string>
</array>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
Expand Down
1 change: 1 addition & 0 deletions Projects/App/Config/Test/Ugglan.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:hedvigtest.page.link</string>
<string>applinks:dev.hedvigit.com</string>
</array>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
Expand Down
7 changes: 2 additions & 5 deletions Projects/App/Sources/Journeys/LoggedInNavigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,10 @@ class LoggedInNavigationViewModel: ObservableObject {
case .addon:
handleAddon(url: url)
case nil:
let rootUrls = [hGraphQL.Environment.staging.deepLinkUrl, Environment.production.deepLinkUrl]
.compactMap({ $0.host })
guard rootUrls.contains(url.host ?? "") else {
let isDeeplink = hGraphQL.Environment.current.isDeeplink(url)
if !isDeeplink {
openUrl(url: url)
return
}

}
}
}
Expand Down
9 changes: 6 additions & 3 deletions Projects/Home/Sources/Models/HelpCenterModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ public struct Question: Codable, Equatable, Hashable, Sendable {
of: Environment.production.webBaseURL.host!,
with: Environment.staging.webBaseURL.host!
)
.replacingOccurrences(
of: Environment.production.deepLinkUrl.host!,
with: Environment.staging.deepLinkUrl.host!
for deeplinkWithIndex in Environment.production.deepLinkUrls.enumerated() {
let index = deeplinkWithIndex.offset
answer = answer.replacingOccurrences(
of: deeplinkWithIndex.element.host!,
with: Environment.staging.deepLinkUrls[index].host!
)
}
}
self.questionEn = questionEn
self.question = question
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class TerminationFlowNavigationViewModel: ObservableObject, @preconcurren
switch redirectAction {
case .updateAddress:
self.router.dismiss()
var url = Environment.current.deepLinkUrl
var url = Environment.current.deepLinkUrls.last!
url.appendPathComponent(DeepLink.moveContract.rawValue)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
NotificationCenter.default.post(name: .openDeepLink, object: url)
Expand Down
11 changes: 5 additions & 6 deletions Projects/hCore/Sources/DeepLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,17 @@ public enum DeepLink: String, Codable, CaseIterable {
}
@MainActor
public static func getType(from url: URL) -> DeepLink? {
let rootUrls = [Environment.staging.deepLinkUrl, Environment.production.deepLinkUrl].compactMap({ $0.host })
guard rootUrls.contains(url.host ?? "") else { return nil }

guard let type = url.pathComponents.compactMap({ DeepLink(rawValue: $0) }).first else {
guard Environment.staging.isDeeplink(url) || Environment.production.isDeeplink(url) else { return nil }
guard let type = url.pathComponents.compactMap({ DeepLink(rawValue: $0) }).last else {
return nil
}
return type
}

public static func getUrl(from deeplink: DeepLink) -> URL? {
let path = Environment.current.deepLinkUrl.absoluteString + "/" + deeplink.rawValue
guard let url = URL(string: path) else {
let paths = Environment.current.deepLinkUrls.compactMap({ $0.absoluteString + "/" + deeplink.rawValue })
let url = paths.compactMap({ URL.init(string: $0) }).last
guard let url else {
return nil
}
return url
Expand Down
5 changes: 4 additions & 1 deletion Projects/hCore/Sources/String+isDeepLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ extension String {
if let match = detector?
.firstMatch(in: self, options: [], range: NSRange(location: 0, length: utf16.count))
{
return match.range.length == utf16.count && contains(Environment.current.deepLinkUrl.host!)
if let url = URL(string: self), Environment.current.isDeeplink(url) {
return match.range.length == utf16.count
}
return false
} else {
return false
}
Expand Down
21 changes: 17 additions & 4 deletions Projects/hGraphQL/Sources/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,27 @@ public enum Environment: Hashable {
}
}

public var deepLinkUrl: URL {
public var deepLinkUrls: [URL] {
switch self {
case .staging: return URL(string: "https://hedvigtest.page.link")!
case .production: return URL(string: "https://hedvig.page.link")!
case .custom(_, _, _, _): return URL(string: "https://hedvig.page.link")!
case .staging:
return [URL(string: "https://hedvigtest.page.link")!, URL(string: "https://dev.hedvigit.com/deeplink/")!]
case .production:
return [URL(string: "https://hedvig.page.link")!, URL(string: "https://www.hedvig.com/deeplink/")!]
case .custom(_, _, _, _):
return [URL(string: "https://hedvig.page.link")!, URL(string: "https://www.hedvig.com/deeplink/")!]
}
}

public func isDeeplink(_ url: URL) -> Bool {
if deepLinkUrls[0].host == url.host {
return true
}
if deepLinkUrls[1].host == url.host {
return url.pathComponents.contains("deeplink")
}
return false
}

public var appStoreURL: URL {
return URL(string: "https://apps.apple.com/se/app/hedvig/id1303668531")!
}
Expand Down
Loading