Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ CI.swift
*.mdb
.build/arm64-apple-macosx/debug/IterableSDK.build/output-file-map.json
.build

agent/
19 changes: 15 additions & 4 deletions swift-sdk/Internal/DeepLinkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,28 @@ class DeepLinkManager: NSObject {

if isIterableDeepLink(appLinkURL.absoluteString) {
redirectUrlSession.makeDataRequest(with: appLinkURL) { [unowned self] _, _, error in
if let error = error {
ITBError("error: \(error.localizedDescription)")
fulfill.resolve(with: (nil, nil))
} else {
// Check if we successfully captured redirect data FIRST
// The delegate callback happens before the error, so deepLinkLocation
// may be set even if we get NSURLErrorTimedOut (-1001) or
// NSURLErrorCancelled (-999) from cancelling the redirect
if self.deepLinkLocation != nil {
Comment on lines +72 to +76
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that the deepLinkLocation is updated on the onRedirect delegate method. It's just weird that we are conditioning the logic of this makeDataRequest completionHandler be dependent on something happening elsewhere.

Logically I think this makes sense, but is there a way for us to better document this in code or use a different architecture to ensure it makes sense to disregard an error on a networkRequest completionHandler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well i wouldnt recommend refactoring but logically it means that we have a redirect url we use it no matter what the http connection or tcp connection returns. Its more robust than before

// We successfully intercepted the redirect
if let deepLinkCampaignId = self.deepLinkCampaignId,
let deepLinkTemplateId = self.deepLinkTemplateId,
let deepLinkMessageId = self.deepLinkMessageId {
fulfill.resolve(with: (self.deepLinkLocation, IterableAttributionInfo(campaignId: deepLinkCampaignId, templateId: deepLinkTemplateId, messageId: deepLinkMessageId)))
} else {
// We have location but missing attribution cookies
// This is still a success case - user can navigate to the deep link
fulfill.resolve(with: (self.deepLinkLocation, nil))
}
} else if let error = error {
// Only treat as error if we didn't capture the redirect location
ITBError("error: \(error.localizedDescription)")
fulfill.resolve(with: (nil, nil))
} else {
// No redirect, no error - shouldn't happen but handle gracefully
fulfill.resolve(with: (nil, nil))
}
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions swift-sdk/Internal/Network/NetworkSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ extension RedirectNetworkSession: URLSessionDelegate, URLSessionTaskDelegate {

guard let headerFields = response.allHeaderFields as? [String: String] else {
delegate?.onRedirect(deepLinkLocation: deepLinkLocation, campaignId: campaignId, templateId: templateId, messageId: messageId)
completionHandler(nil)
return
}

guard let url = response.url else {
delegate?.onRedirect(deepLinkLocation: deepLinkLocation, campaignId: campaignId, templateId: templateId, messageId: messageId)
completionHandler(nil)
Comment on lines +117 to +123
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the nil completionHandler here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats just a bug that was there the completionhandler wasnt fired if there was no info in the headers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! So, to double check, what we want is (as per the documentation) to pass nil on the completionHandler so we let "the body of the redirection response to be delivered as the payload of this request" correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basically completion handler should be always fired before returning here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we pass nil on the completionHandler to not follow any further redirects the redirection is passed in the delegate callbacks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but effectively yes when the conpletionHandler(nil) is fired it would finish the redirection flow

return
}

Expand Down
Loading