Commit c21e87c1 by Demid Merzlyakov

IOS-74: AppsFlyer deep links handling.

parent c6a643bf
......@@ -38,6 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
appsFlyer.appsFlyerDevKey = kAppsFlyerId
appsFlyer.appleAppID = kAppsFlyerAppId
appsFlyer.delegate = self
appsFlyer.deepLinkDelegate = self
#if DEBUG
appsFlyer.isDebug = true
#else
......@@ -53,7 +54,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
if let userQualifiedDate = Settings.shared.userQualifiedDate {
let timeSinceQualified = Date().timeIntervalSince(userQualifiedDate)
let day = TimeInterval(3600 * 24)
if timeSinceQualified >= 3 * day && timeSinceQualified < 6 * day {
......@@ -106,15 +106,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
log.info("Open URL: \(url) with options: \(options)")
//TODO: move to Router?
#if DEBUG
//TODO: REMOVE THIS'
//TODO: move to Router?
#warning("THIS IS A DEBUG-ONLY PIECE OF CODE! Not even temporary! Remove before making a production build.")
#else
#error("THIS IS A DEBUG-ONLY PIECE OF CODE! Not even temporary! Remove before making a production build.")
#endif
appsFlyer.handleOpen(url, options: options)
let oneWeatherRouter = DeeplinksRouter()
oneWeatherRouter.open(url: url)
return true
}
......@@ -166,3 +160,38 @@ extension AppDelegate: AppsFlyerLibDelegate {
appsFlyerLog.error("app open attribution error: \(error)")
}
}
extension AppDelegate: DeepLinkDelegate {
func didResolveDeepLink(_ result: DeepLinkResult) {
switch result.status {
case .notFound:
appsFlyerLog.info("Deeplink: not found")
return
case .failure:
if let error = result.error {
appsFlyerLog.error("Deeplink: error: \(error)")
}
else {
appsFlyerLog.error("Deeplink: error (unknown)")
}
return
case .found:
appsFlyerLog.info("Deeplink: found!")
}
guard let deepLinkObj:DeepLink = result.deepLink else {
appsFlyerLog.error("Deeplink: Could not extract deep link object")
return
}
log.debug("Deeplink: it's a \(deepLinkObj.isDeferred ? "deferred" : "direct") deeplink.")
guard let deeplink = deepLinkObj.deeplinkValue else {
appsFlyerLog.error("Deeplink: Could not extract deep_link_value from deep link object")
return
}
guard let url = URL(string: deeplink) else {
appsFlyerLog.error("Deeplink: Couldn't create a URL from deeplink: \(deeplink)")
return
}
let router = DeeplinksRouter()
router.open(url: url)
}
}
......@@ -6,7 +6,8 @@
// Copyright © 2021 OneLouder, Inc. All rights reserved.
//
import Foundation
import UIKit
import AppsFlyerLib
class DeeplinksRouter {
static let urlScheme = "oneweather"
......@@ -80,13 +81,17 @@ class DeeplinksRouter {
return result
}
public func open(url: URL) {
public func open(url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) {
guard self.is1WUrl(url) else {
log.info("not 1Weather URL, ignore: \(url)")
log.info("not 1Weather URL, trying AppsFlyer: \(url)")
AppsFlyerLib.shared().handleOpen(url, options: options)
return
}
log.info("open URL: \(url)")
log.info("open 1Weather URL: \(url)")
var pathComponents = url.pathComponents
if let host = url.host {
pathComponents.insert(host, at: 0)
}
while let currentComponent = pathComponents.popLast() {
if let parsedComponent = UrlPathComponent(rawValue: currentComponent.lowercased()) {
log.debug("Parsed path: \(parsedComponent.rawValue)")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment