Skip to content

Remove long-unused Iterable deep links handling #24487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
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
1 change: 0 additions & 1 deletion Sources/Reader/Reader.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<array>
<string>webcredentials:wordpress.com</string>
<string>webcredentials:*.wordpress.com</string>
<string>applinks:links.wp.a8cmail.com</string>
</array>
<key>aps-environment</key>
<string>development</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ extension WPTabBarController: RootViewPresenter {
}

func showNotificationsTab(completion: ((NotificationsViewController) -> Void)?) {
self.selectedIndex = WPTab.notifications.rawValue
completion?(self.notificationsViewController!)
// UITabBarController.selectedIndex must be used from main thread only.
DispatchQueue.main.async { [weak self] in
guard let self else { return }

self.selectedIndex = WPTab.notifications.rawValue
completion?(self.notificationsViewController!)
}
Comment on lines -25 to +31
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noticed this when running Jetpack in the Simulator and opening the app simulating a user deep link via xcrun simctl openurl booted https://wordpress.com/notifications

image

I considered moving the main thread dispatch earlier on, e.g. in the deep link handling

diff --git a/WordPress/Classes/System/WordPressAppDelegate.swift b/WordPress/Classes/System/WordPressAppDelegate.swift
index 8167daf7b1..6b9a57642a 100644
--- a/WordPress/Classes/System/WordPressAppDelegate.swift
+++ b/WordPress/Classes/System/WordPressAppDelegate.swift
@@ -457,7 +457,9 @@ extension WordPressAppDelegate {
         }
 
         trackDeepLink(for: url) { url in
-            UniversalLinkRouter.shared.handle(url: url)
+            DispatchQueue.main.async {
+                UniversalLinkRouter.shared.handle(url: url)
+            }
         }
     }

but I thought it best to be precise and keep the main thread dispatching as close to the code requiring it as possible.

However, forcing the deep link handling to run on the main thread might be a good blanket approach if we fear that other deep link might implicitly require the main thread.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest adding DispatchQueue.main.async in trackDeepLink as you originally wanted and adding wpAssert(Thread.isMainThread) in showNotificationsTab. In the future, we'll try and use @MainActor as much as we can.

Adding an async in showNotificationsTab is too risky because it has many callers, and some of them might rely on it executing synchronously.

}

// MARK: Me
Expand Down
19 changes: 5 additions & 14 deletions WordPress/Classes/System/WordPressAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -473,24 +473,15 @@ extension WordPressAppDelegate {
extension WordPressAppDelegate {

private func trackDeepLink(for url: URL, completion: @escaping ((URL) -> Void)) {
guard isIterableDeepLink(url) else {
completion(url)
return
}

let task = URLSession.shared.dataTask(with: url) {(_, response, error) in
if let url = response?.url {
completion(url)
let task = URLSession.shared.dataTask(with: url) { _, response, error in
guard let url = response?.url else {
return
}

completion(url)
Comment on lines +477 to +481
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copilot observed:

The URLSession data task does not call the completion handler if response?.url is nil, which could lead to unexpected behavior. Consider adding a fallback call to the completion handler (or an error callback) when the response URL is unavailable.

That's a good point actually. I don't think it's in scope for this PR, but we might want to log a ticket to look into it. Unless... how can we get to the point where a deep link has a response without URL? Is this a legacy from the Objective-C NSURLResponse implementation?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you never expect it to happen, let's add wpAssertionFailure.

}
task.resume()
}

private func isIterableDeepLink(_ url: URL) -> Bool {
return url.absoluteString.contains(WordPressAppDelegate.iterableDomain)
}

private static let iterableDomain = "links.wp.a8cmail.com"
}

// MARK: - Helpers
Expand Down
1 change: 0 additions & 1 deletion WordPress/Jetpack/JetpackDebug.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<string>applinks:wordpress.com</string>
<string>applinks:*.wordpress.com</string>
<string>applinks:public-api.wordpress.com</string>
<string>applinks:links.wp.a8cmail.com</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
Expand Down
1 change: 0 additions & 1 deletion WordPress/Jetpack/JetpackRelease-Alpha.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<string>applinks:wordpress.com</string>
<string>applinks:*.wordpress.com</string>
<string>applinks:public-api.wordpress.com</string>
<string>applinks:links.wp.a8cmail.com</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
Expand Down
1 change: 0 additions & 1 deletion WordPress/Jetpack/JetpackRelease.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<string>applinks:wordpress.com</string>
<string>applinks:*.wordpress.com</string>
<string>applinks:public-api.wordpress.com</string>
<string>applinks:links.wp.a8cmail.com</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
Expand Down
1 change: 0 additions & 1 deletion WordPress/WordPress-Alpha.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<array>
<string>webcredentials:wordpress.com</string>
<string>webcredentials:*.wordpress.com</string>
<string>applinks:links.wp.a8cmail.com</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
Expand Down
1 change: 0 additions & 1 deletion WordPress/WordPress.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<array>
<string>webcredentials:wordpress.com</string>
<string>webcredentials:*.wordpress.com</string>
<string>applinks:links.wp.a8cmail.com</string>
</array>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
Expand Down