Skip to content
Snippets Groups Projects
Commit eb32886a authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Switches from deeplinking to universal link

parent a13b40cc
No related branches found
No related tags found
3 merge requests!71Releasing v1.1.5 (214),!67v1.1.5 b(203),!61Switches from deeplinking to universal link
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
<dict> <dict>
<key>aps-environment</key> <key>aps-environment</key>
<string>development</string> <string>development</string>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:xx.network</string>
</array>
<key>com.apple.developer.icloud-container-identifiers</key> <key>com.apple.developer.icloud-container-identifiers</key>
<array> <array>
<string>iCloud.xxm-cloud</string> <string>iCloud.xxm-cloud</string>
......
...@@ -142,21 +142,32 @@ public class AppDelegate: UIResponder, UIApplicationDelegate { ...@@ -142,21 +142,32 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
open url: URL, open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:] options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool { ) -> Bool {
if let username = getUsernameFromInvitationDeepLink(url) { dropboxService.handleOpenUrl(url)
let router = try! DependencyInjection.Container.shared.resolve() as PushRouter }
router.navigateTo(.search(username: username), {})
return true public func application(
} else { _ application: UIApplication,
return dropboxService.handleOpenUrl(url) continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL,
let username = getUsernameFromInvitationDeepLink(incomingURL) else {
return false
} }
let router = try! DependencyInjection.Container.shared.resolve() as PushRouter
router.navigateTo(.search(username: username), {})
return true
} }
} }
func getUsernameFromInvitationDeepLink(_ url: URL) -> String? { func getUsernameFromInvitationDeepLink(_ url: URL) -> String? {
if let components = URLComponents(url: url, resolvingAgainstBaseURL: false), if let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
components.scheme == "xxnetwork", components.scheme == "https",
components.host == "messenger", components.host == "xx.network",
let queryItem = components.queryItems?.first(where: { $0.name == "invitation" }), components.path == "/messenger/invitation",
let queryItem = components.queryItems?.first(where: { $0.name == "username" }),
let username = queryItem.value { let username = queryItem.value {
return username return username
} }
......
...@@ -42,6 +42,6 @@ final class MenuViewModel { ...@@ -42,6 +42,6 @@ final class MenuViewModel {
} }
var referralDeeplink: String { var referralDeeplink: String {
"xxnetwork://messenger?invitation=\(username)" "https://xx.network/messenger/invitation?username=\(username)"
} }
} }
...@@ -3,19 +3,33 @@ import XCTest ...@@ -3,19 +3,33 @@ import XCTest
@testable import App @testable import App
final class AppDelegateTests: XCTestCase { final class AppDelegateTests: XCTestCase {
func test_invitationDeeplink() { func test_invitationUniversalLink() {
XCTAssertNil( XCTAssertNil(getUsernameFromInvitationDeepLink(
getUsernameFromInvitationDeepLink(URL(string: "http://messenger?invitation=john_doe")!) URL(string: "https://xx.network/messenger/invite?username=some")!
) ))
XCTAssertNotEqual( XCTAssertNil(getUsernameFromInvitationDeepLink(
getUsernameFromInvitationDeepLink(URL(string: "xxnetwork://messenger?invitation=the_rock")!), URL(string: "http://xx.network/messenger/invitation?username=some")!
"john_doe" ))
)
XCTAssertNil(getUsernameFromInvitationDeepLink(
XCTAssertEqual( URL(string: "https://network.xx/messenger/invitation?username=some")!
getUsernameFromInvitationDeepLink(URL(string: "xxnetwork://messenger?invitation=john_doe")!), ))
"john_doe"
) XCTAssertEqual(getUsernameFromInvitationDeepLink(
URL(string: "https://xx.network/messenger/invitation?username=brad")!
), "brad")
XCTAssertNil(getUsernameFromInvitationDeepLink(
URL(string: "https://xx.network/messenger/invitation?password=value")!
))
XCTAssertNil(getUsernameFromInvitationDeepLink(
URL(string: "https://xx.network/xxmessenger/invitation?username=some")!
))
XCTAssertNotEqual(getUsernameFromInvitationDeepLink(
URL(string: "https://xx.network/messenger/invitation?username=anderson")!
), "silva")
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment