Skip to content

Commit

Permalink
Merge pull request #4926 from wikimedia/T371983
Browse files Browse the repository at this point in the history
Fix deep links
  • Loading branch information
mazevedofs authored Aug 16, 2024
2 parents 26094dc + 4a57a14 commit fa40e8a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
4 changes: 0 additions & 4 deletions Wikipedia/Code/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationWillTerminate(_ application: UIApplication) {
updateDynamicIconShortcutItems()
}

func application(_ application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool {
return true
}

// MARK: UISceneSession Lifecycle

Expand Down
2 changes: 2 additions & 0 deletions Wikipedia/Code/NavigationStateController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ final class NavigationStateController: NSObject {
}

guard let articleViewController = visibleArticleViewController(for: selectedNavigationController) else {
moc.navigationState = nil
return
}

let info = Info(articleKey: articleViewController.articleURL.wmf_databaseKey)

guard let stateToPersist = NavigationState.ViewController(kind: .article, presentation: .push, info: info) else {
moc.navigationState = nil
return
}

Expand Down
29 changes: 27 additions & 2 deletions Wikipedia/Code/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
return
}

// scene(_ scene: UIScene, continue userActivity: NSUserActivity) and
// scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>)
// windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void)
// are not called upon terminated state, so we need to handle them explicitly here.
if let userActivity = connectionOptions.userActivities.first {
processUserActivity(userActivity)
} else if !connectionOptions.urlContexts.isEmpty {
openURLContexts(connectionOptions.urlContexts)
} else if let shortcutItem = connectionOptions.shortcutItem {
processShortcutItem(shortcutItem)
}

UNUserNotificationCenter.current().delegate = appViewController
appViewController.launchApp(in: window, waitToResumeApp: appNeedsResume)
}
Expand Down Expand Up @@ -63,10 +75,20 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}

func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
appViewController?.processShortcutItem(shortcutItem, completion: completionHandler)
processShortcutItem(shortcutItem, completionHandler: completionHandler)
}

private func processShortcutItem(_ shortcutItem: UIApplicationShortcutItem, completionHandler: ((Bool) -> Void)? = nil) {
appViewController?.processShortcutItem(shortcutItem) { handled in
completionHandler?(handled)
}
}

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
processUserActivity(userActivity)
}

private func processUserActivity(_ userActivity: NSUserActivity) {
guard let appViewController else {
return
}
Expand Down Expand Up @@ -99,7 +121,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {

openURLContexts(URLContexts)
}

private func openURLContexts(_ URLContexts: Set<UIOpenURLContext>) {
guard let appViewController else {
return
}
Expand Down
4 changes: 1 addition & 3 deletions Wikipedia/Code/WMFAppViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,7 @@ - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
#pragma mark - Notifications

- (void)appWillEnterForegroundWithNotification:(NSNotification *)note {
// Don't access anything that can't be accessed in the background without starting a background task. For example, don't use anything in the shared app container like all of the Core Data persistent stores
self.unprocessedUserActivity = nil;
self.unprocessedShortcutItem = nil;

}

// When the user launches from a terminated state, resume might not finish before didBecomeActive, so these tasks are held until both items complete
Expand Down
6 changes: 3 additions & 3 deletions docs/url_schemes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ The URL scheme is `wikipedia://`. The following URLs are currently handled:
| ------------------ | ---------------------------------------- | ---------------------------------------- |
| Article | wikipedia://[site]/wiki/[page_id] | wikipedia://en.wikipedia.org/wiki/Red |
| | https://[[site]/wiki/[page_id] | https://en.wikipedia.org/wiki/Red |
| Content | wikipedia://content | |
| Content | wikipedia://content | wikipedia://content/on-this-day/wikipedia.org/en/2024/08/15 |
| Explore | wikipedia://explore | |
| History | wikipedia://history | |
| Places | wikipedia://places[?WMFArticleURL=] | |
| Places | wikipedia://places[?WMFArticleURL=] | wikipedia://places/?WMFArticleURL=https://en.wikipedia.org/wiki/Dallas
|
| Saved pages | wikipedia://saved | |
| Search | wikipedia://[site]/w/index.php?search=[query] | wikipedia://en.wikipedia.org/w/index.php?search=dog |

0 comments on commit fa40e8a

Please sign in to comment.