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 @@
<dict>
<key>aps-environment</key>
<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>
<array>
<string>iCloud.xxm-cloud</string>
......
......@@ -142,21 +142,32 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
if let username = getUsernameFromInvitationDeepLink(url) {
let router = try! DependencyInjection.Container.shared.resolve() as PushRouter
router.navigateTo(.search(username: username), {})
return true
} else {
return dropboxService.handleOpenUrl(url)
dropboxService.handleOpenUrl(url)
}
public func application(
_ application: UIApplication,
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? {
if let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
components.scheme == "xxnetwork",
components.host == "messenger",
let queryItem = components.queryItems?.first(where: { $0.name == "invitation" }),
components.scheme == "https",
components.host == "xx.network",
components.path == "/messenger/invitation",
let queryItem = components.queryItems?.first(where: { $0.name == "username" }),
let username = queryItem.value {
return username
}
......
......@@ -42,6 +42,6 @@ final class MenuViewModel {
}
var referralDeeplink: String {
"xxnetwork://messenger?invitation=\(username)"
"https://xx.network/messenger/invitation?username=\(username)"
}
}
......@@ -3,19 +3,33 @@ import XCTest
@testable import App
final class AppDelegateTests: XCTestCase {
func test_invitationDeeplink() {
XCTAssertNil(
getUsernameFromInvitationDeepLink(URL(string: "http://messenger?invitation=john_doe")!)
)
XCTAssertNotEqual(
getUsernameFromInvitationDeepLink(URL(string: "xxnetwork://messenger?invitation=the_rock")!),
"john_doe"
)
XCTAssertEqual(
getUsernameFromInvitationDeepLink(URL(string: "xxnetwork://messenger?invitation=john_doe")!),
"john_doe"
)
func test_invitationUniversalLink() {
XCTAssertNil(getUsernameFromInvitationDeepLink(
URL(string: "https://xx.network/messenger/invite?username=some")!
))
XCTAssertNil(getUsernameFromInvitationDeepLink(
URL(string: "http://xx.network/messenger/invitation?username=some")!
))
XCTAssertNil(getUsernameFromInvitationDeepLink(
URL(string: "https://network.xx/messenger/invitation?username=some")!
))
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