Skip to content

Commit

Permalink
fix(ad-hoc): remove universal links support (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-vysotskyi-cko authored Dec 14, 2023
1 parent 9cb45ff commit 74ac418
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
6 changes: 0 additions & 6 deletions Example/Example/Sources/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIOpenURLContext>) {
if let url = urlContexts.first?.url {
ProcessOut.shared.processDeepLink(url: url)
Expand Down
8 changes: 4 additions & 4 deletions Sources/ProcessOut/ProcessOut.docc/3DS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func handle(redirect: PO3DSRedirect, completion: @escaping (Result<String, POFai
}
```

When using `PO3DSRedirectViewControllerBuilder` your application should support deep and/or universal links. When
When using `PO3DSRedirectViewControllerBuilder` your application should support deep links. When
application receives incoming URL you should allow ProcessOut SDK to handle it. For example if you are using scene
delegate and universal links it may look like following:
delegate it may look like following:

```swift
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
guard let url = userActivity.webpageURL else {
func scene(_ scene: UIScene, openURLContexts urlContexts: Set<UIOpenURLContext>) {
guard let url = urlContexts.first?.url else {
return
}
let isHandled = ProcessOut.shared.processDeepLink(url: url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import Foundation

struct DeepLinkReceivedEvent: EventEmitterEvent {

/// Url representing deep link or universal link.
/// Url representing deep link.
let url: URL
}
7 changes: 4 additions & 3 deletions Sources/ProcessOut/Sources/Api/ProcessOut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Foundation

final class LocalEventEmitter: EventEmitter, @unchecked Sendable {

init() {
init(logger: POLogger) {
self.logger = logger
lock = NSLock()
subscriptions = [:]
}
Expand All @@ -18,19 +19,20 @@ final class LocalEventEmitter: EventEmitter, @unchecked Sendable {

func emit<Event: EventEmitterEvent>(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
}

Expand Down Expand Up @@ -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]]
}

0 comments on commit 74ac418

Please sign in to comment.