iOS: gescannter Einzelstück-Link öffnet wirklich das Stück

Universal Link oeffnete die App, sprang aber nicht aufs Stueck. Jetzt robuster:
- Kaltstart wird abgefangen (AppDelegate application(_:continue:) + pending-URL),
  zusaetzlich zu den SwiftUI-Hooks.
- Beim Link wird auf das Server-Profil gewechselt, dessen Adresse zum Host passt
  (sonst wuerde die UID am falschen Server gesucht).
- Schlaegt das Aufloesen fehl (nicht angemeldet, UID unbekannt), erscheint jetzt
  eine Meldung statt stiller Nichtreaktion.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-07-26 10:24:05 +02:00
parent b4b203a117
commit 2d7cfa7fcb
3 changed files with 49 additions and 1 deletions

View File

@@ -40,6 +40,8 @@ final class Router: ObservableObject {
}
let parts = url.pathComponents // z.B. ["/", "i", "ABC123"]
if let idx = parts.firstIndex(of: "i"), idx + 1 < parts.count {
// Auf den Server aus dem Link wechseln, damit die UID dort gesucht wird.
Session.shared.switchToProfile(matching: url)
openItemUid = parts[idx + 1].uppercased()
}
}
@@ -73,6 +75,11 @@ struct VorraniaApp: App {
router.handle(expiryProfile: profile)
AppDelegate.pendingExpiryProfile = nil
}
// Kaltstart aus einem gescannten Universal Link.
if let url = AppDelegate.pendingURL {
router.handle(url: url)
AppDelegate.pendingURL = nil
}
}
.onReceive(NotificationCenter.default.publisher(for: AppDelegate.shortcutNotification)) { note in
if let type = note.object as? String { router.handle(shortcut: type) }
@@ -80,6 +87,9 @@ struct VorraniaApp: App {
.onReceive(NotificationCenter.default.publisher(for: AppDelegate.expiryTapNotification)) { note in
if let profile = note.object as? String { router.handle(expiryProfile: profile) }
}
.onReceive(NotificationCenter.default.publisher(for: AppDelegate.urlNotification)) { note in
if let url = note.object as? URL { router.handle(url: url) }
}
}
// Im Vordergrund den Meldungsplan auffrischen und den naechsten
// Hintergrundlauf einplanen.
@@ -101,8 +111,10 @@ struct VorraniaApp: App {
final class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
static let shortcutNotification = Notification.Name("VorraniaShortcut")
static let expiryTapNotification = Notification.Name("VorraniaExpiryTap")
static let urlNotification = Notification.Name("VorraniaOpenURL")
static var pendingShortcut: String?
static var pendingExpiryProfile: String?
static var pendingURL: URL?
static let refreshTaskID = "com.scarriffle.vorrania.refresh"
@@ -132,6 +144,17 @@ final class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCent
completionHandler(true)
}
// Universal Link (/i/<UID>) auch beim Kaltstart, falls die SwiftUI-Hooks
// ihn nicht mitbekommen.
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL else { return false }
AppDelegate.pendingURL = url
NotificationCenter.default.post(name: AppDelegate.urlNotification, object: url)
return true
}
// MARK: - Benachrichtigungen
/// Auch im Vordergrund als Banner zeigen - sonst bliebe eine faellige