Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions swift-sdk/Internal/DeepLinkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DeepLinkManager: NSObject {
urlDelegate: IterableURLDelegate?,
urlOpener: UrlOpenerProtocol,
allowedProtocols: [String] = []) -> (Bool, Pending<IterableAttributionInfo?, Error>) {
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 {
Expand Down Expand Up @@ -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)")
Expand All @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions swift-sdk/SDK/IterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions tests/unit-tests/DeepLinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading