diff --git a/swift-sdk/Internal/DeepLinkManager.swift b/swift-sdk/Internal/DeepLinkManager.swift index 42c914a54..99fe24b6e 100644 --- a/swift-sdk/Internal/DeepLinkManager.swift +++ b/swift-sdk/Internal/DeepLinkManager.swift @@ -17,7 +17,7 @@ class DeepLinkManager: NSObject { urlDelegate: IterableURLDelegate?, urlOpener: UrlOpenerProtocol, allowedProtocols: [String] = []) -> (Bool, Pending) { - if isIterableDeepLink(url.absoluteString) { + if DeepLinkManager.isIterableDeepLink(url.absoluteString) { let pending = resolve(appLinkURL: url).map { (resolvedUrl, attributionInfo) -> IterableAttributionInfo? in var resolvedUrlString: String if let resolvedUrl = resolvedUrl { @@ -67,7 +67,7 @@ class DeepLinkManager: NSObject { deepLinkTemplateId = nil deepLinkMessageId = nil - if isIterableDeepLink(appLinkURL.absoluteString) { + if DeepLinkManager.isIterableDeepLink(appLinkURL.absoluteString) { redirectUrlSession.makeDataRequest(with: appLinkURL) { [unowned self] _, _, error in if let error = error { ITBError("error: \(error.localizedDescription)") @@ -89,7 +89,7 @@ class DeepLinkManager: NSObject { return fulfill } - private func isIterableDeepLink(_ urlString: String) -> Bool { + static func isIterableDeepLink(_ urlString: String) -> Bool { guard let regex = try? NSRegularExpression(pattern: Const.deepLinkRegex, options: []) else { return false } diff --git a/swift-sdk/SDK/IterableAPI.swift b/swift-sdk/SDK/IterableAPI.swift index e2bb235bd..87bae1202 100644 --- a/swift-sdk/SDK/IterableAPI.swift +++ b/swift-sdk/SDK/IterableAPI.swift @@ -152,6 +152,16 @@ import UIKit implementation?.setUserId(userId, authToken: authToken, successHandler: successHandler, failureHandler: failureHandler, identityResolution: identityResolution) } + /// Checks if a URL is an Iterable deep link + /// + /// - Parameters: + /// - urlString: The URL string to check + /// + /// - Returns: `true` if the URL matches the Iterable deep link pattern + public static func isIterableDeepLink(_ urlString: String) -> Bool { + DeepLinkManager.isIterableDeepLink(urlString) + } + /// Handle a Universal Link /// /// For Iterable links, it will track the click and retrieve the original URL, diff --git a/tests/unit-tests/DeepLinkTests.swift b/tests/unit-tests/DeepLinkTests.swift index 6674bc3e2..d981f509f 100644 --- a/tests/unit-tests/DeepLinkTests.swift +++ b/tests/unit-tests/DeepLinkTests.swift @@ -132,6 +132,26 @@ class DeepLinkTests: XCTestCase { wait(for: [expectation1], timeout: testExpectationTimeout) } + // MARK: - isIterableDeepLink Tests + + func testIsIterableDeepLinkReturnsTrueForValidDeepLink() { + XCTAssertTrue(IterableAPI.isIterableDeepLink(iterableRewriteURL)) + } + + func testIsIterableDeepLinkReturnsFalseForNonRewriteLink() { + XCTAssertFalse(IterableAPI.isIterableDeepLink(iterableNoRewriteURL)) + } + + func testIsIterableDeepLinkReturnsFalseForNonIterableLink() { + XCTAssertFalse(IterableAPI.isIterableDeepLink("https://example.com/some/path")) + } + + func testIsIterableDeepLinkReturnsFalseForEmptyString() { + XCTAssertFalse(IterableAPI.isIterableDeepLink("")) + } + + // MARK: - Other Tests + /// this is a service that automatically redirects if that url is hit, make sure we are not actually hitting the url but our servers func testNoURLRedirect() { let expectation1 = expectation(description: "testNoURLRedirect")