diff --git a/Example/Example/Sources/Application/SceneDelegate.swift b/Example/Example/Sources/Application/SceneDelegate.swift index 2b35942ec..0619074f0 100644 --- a/Example/Example/Sources/Application/SceneDelegate.swift +++ b/Example/Example/Sources/Application/SceneDelegate.swift @@ -23,12 +23,6 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate { window?.makeKeyAndVisible() } - func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { - if let url = userActivity.webpageURL { - ProcessOut.shared.processDeepLink(url: url) - } - } - func scene(_ scene: UIScene, openURLContexts urlContexts: Set) { if let url = urlContexts.first?.url { ProcessOut.shared.processDeepLink(url: url) diff --git a/Sources/ProcessOut/ProcessOut.docc/3DS.md b/Sources/ProcessOut/ProcessOut.docc/3DS.md index f826e8bfb..3a8bbd2c0 100644 --- a/Sources/ProcessOut/ProcessOut.docc/3DS.md +++ b/Sources/ProcessOut/ProcessOut.docc/3DS.md @@ -36,13 +36,13 @@ func handle(redirect: PO3DSRedirect, completion: @escaping (Result) { + guard let url = urlContexts.first?.url else { return } let isHandled = ProcessOut.shared.processDeepLink(url: url) diff --git a/Sources/ProcessOut/Sources/Api/Models/DeepLinkReceivedEvent.swift b/Sources/ProcessOut/Sources/Api/Models/DeepLinkReceivedEvent.swift index 2b2bb4ccf..938dff6b9 100644 --- a/Sources/ProcessOut/Sources/Api/Models/DeepLinkReceivedEvent.swift +++ b/Sources/ProcessOut/Sources/Api/Models/DeepLinkReceivedEvent.swift @@ -9,6 +9,6 @@ import Foundation struct DeepLinkReceivedEvent: EventEmitterEvent { - /// Url representing deep link or universal link. + /// Url representing deep link. let url: URL } diff --git a/Sources/ProcessOut/Sources/Api/ProcessOut.swift b/Sources/ProcessOut/Sources/Api/ProcessOut.swift index 6261be056..ac9a05b5f 100644 --- a/Sources/ProcessOut/Sources/Api/ProcessOut.swift +++ b/Sources/ProcessOut/Sources/Api/ProcessOut.swift @@ -77,12 +77,13 @@ public final class ProcessOut { return DefaultCustomerTokensService(repository: repository, threeDSService: threeDSService) }() - /// Call this method in your app or scene delegate whenever your implementation receives incoming URL. You can pass - /// both custom scheme-based deep links and universal links. + /// Call this method in your app or scene delegate whenever your implementation receives incoming URL. Only deep + /// links are supported. /// /// - Returns: `true` if the URL is expected and will be handled by SDK. `false` otherwise. @discardableResult public func processDeepLink(url: URL) -> Bool { + logger.debug("Will process deep link: \(url)") let event = DeepLinkReceivedEvent(url: url) return eventEmitter.emit(event: event) } @@ -101,7 +102,7 @@ public final class ProcessOut { // MARK: - Internal /// Event emitter to use for events exchange. - private(set) lazy var eventEmitter: EventEmitter = LocalEventEmitter() + private(set) lazy var eventEmitter: EventEmitter = LocalEventEmitter(logger: logger) init(configuration: ProcessOutConfiguration) { self.configuration = configuration diff --git a/Sources/ProcessOut/Sources/Core/EventEmitter/LocalEventEmitter.swift b/Sources/ProcessOut/Sources/Core/EventEmitter/LocalEventEmitter.swift index e6b589893..4e7e0a127 100644 --- a/Sources/ProcessOut/Sources/Core/EventEmitter/LocalEventEmitter.swift +++ b/Sources/ProcessOut/Sources/Core/EventEmitter/LocalEventEmitter.swift @@ -9,7 +9,8 @@ import Foundation final class LocalEventEmitter: EventEmitter, @unchecked Sendable { - init() { + init(logger: POLogger) { + self.logger = logger lock = NSLock() subscriptions = [:] } @@ -18,19 +19,20 @@ final class LocalEventEmitter: EventEmitter, @unchecked Sendable { func emit(event: Event) -> Bool { lock.lock() - guard let eventSubscriptions = subscriptions[Event.name]?.values else { + guard let eventSubscriptions = subscriptions[Event.name]?.values, !eventSubscriptions.isEmpty else { lock.unlock() + logger.debug("No subscribers for '\(Event.name)' event, ignored") return false } lock.unlock() - guard !eventSubscriptions.isEmpty else { - return false - } var isHandled = false for subscription in eventSubscriptions { // Event should be delievered to all subscribers. isHandled = subscription.listener(event) || isHandled } + if !isHandled { + logger.debug("Subscribers refused to handle '\(Event.name)' event") + } return isHandled } @@ -83,6 +85,7 @@ final class LocalEventEmitter: EventEmitter, @unchecked Sendable { // MARK: - Private Properties + private let logger: POLogger private let lock: NSLock private var subscriptions: [String: [AnyHashable: Subscription]] }