Zum Inhalt springen
Engineering · · 6 Min. Lesezeit

Plattformspezifisches Link-Routing in plattformübergreifenden Apps

Von Tolinku-Team
|
Plattformspezifisches Link-Routing in Cross-Platform-Apps

Die meisten Deep-Link-Routen funktionieren auf iOS und Android gleich: Dieselbe URL führt zum selben Bildschirm. Manche Routen brauchen aber plattformspezifisches Verhalten. iOS unterstützt eventuell Funktionen, die Android nicht hat (Handoff, Spotlight-Indexierung). Android nutzt oft Intent-basierte Navigation, für die es auf iOS kein Gegenstück gibt. Dieser Artikel zeigt Muster, mit denen du diese Unterschiede behandelst und dein Code wartbar bleibt.

Gemeinsame Routing-Muster findest du unter plattformübergreifende Muster für die Link-Verarbeitung. Den vollständigen Überblick findest du unter Leitfaden zu Cross-Platform Deep Linking für 2026.

Wo sich die Plattformunterschiede zeigen

Das Routing von Deep Links verhält sich auf drei Ebenen plattformspezifisch:

1. URL-Empfang

iOS und Android empfangen Deep Links über unterschiedliche APIs:

Aspekt iOS Android
Mechanismus Universal Links (AASA) App Links (assetlinks.json)
Einstiegspunkt application(_:continue:restorationHandler:) onCreate() / onNewIntent() mit Intent
URL-Format Dieselbe HTTPS-URL Dieselbe HTTPS-URL
Verifizierung AASA-Datei assetlinks.json

2. Navigation

Jede Plattform hat ein eigenes Navigationssystem, das anders funktioniert:

  • iOS nutzt UINavigationController push/pop, UITabBarController, oder SwiftUI NavigationStack.
  • Android nutzt Activities, Fragments und die Navigation Component.
  • Plattformübergreifende Frameworks (React Native, Flutter, Capacitor) verbergen diese Unterschiede meist, zeigen sie aber manchmal doch.

3. Verfügbarkeit der Funktionen

Manche Funktionen gibt es nur auf einer Plattform:

  • Nur iOS: Handoff, Spotlight-Indexierung, Universal Clipboard
  • Nur Android: Instant Apps, Custom-Tabs-Fallback, Multi-Window-Deep-Links
  • Unterschiedliches Verhalten: Behandlung des Zurück-Buttons, Verwaltung des Task-Stacks, Verhalten im Split-Screen

Muster: Plattformabhängige Routenkonfiguration

Definiere Routen und überschreibe bei Bedarf plattformspezifische Werte:

interface Route {
  path: string;
  screen: string;
  platforms: ('ios' | 'android' | 'web')[];
  iosConfig?: {
    handoffActivity?: string;
    spotlightTitle?: string;
  };
  androidConfig?: {
    taskAffinity?: string;
    launchMode?: 'singleTop' | 'singleTask';
  };
}

const routes: Route[] = [
  {
    path: '/products/:productId',
    screen: 'ProductDetail',
    platforms: ['ios', 'android', 'web']
  },
  {
    path: '/ar-preview/:productId',
    screen: 'ARPreview',
    platforms: ['ios'], // nur ARKit
    iosConfig: {
      spotlightTitle: 'AR-Vorschau'
    }
  },
  {
    path: '/instant/:productId',
    screen: 'InstantPreview',
    platforms: ['android'], // Android Instant Apps
    androidConfig: {
      launchMode: 'singleTask'
    }
  },
  {
    path: '/share/:shareId',
    screen: 'SharedContent',
    platforms: ['ios', 'android', 'web'],
    iosConfig: {
      handoffActivity: 'com.yourapp.viewing'
    }
  }
];

Plattformspezifisches Routing implementieren

Gemeinsamer Router mit Plattformfilter

function matchRoute(
  url: string,
  platform: 'ios' | 'android' | 'web'
): RouteMatch | null {
  const parsed = new URL(url);
  const path = parsed.pathname;

  for (const route of routes) {
    // Skip routes not available on this platform
    if (!route.platforms.includes(platform)) continue;

    const match = matchPath(path, route.path);
    if (match) {
      return {
        screen: route.screen,
        params: {
          ...match.params,
          ...Object.fromEntries(parsed.searchParams)
        },
        platformConfig: platform === 'ios'
          ? route.iosConfig
          : route.androidConfig
      };
    }
  }

  return null;
}

function matchPath(
  actual: string,
  pattern: string
): { params: Record<string, string> } | null {
  const paramNames: string[] = [];
  const regex = new RegExp(
    '^' + pattern.replace(/:([^/]+)/g, (_, name) => {
      paramNames.push(name);
      return '([^/]+)';
    }) + '$'
  );

  const match = actual.match(regex);
  if (!match) return null;

  const params: Record<string, string> = {};
  paramNames.forEach((name, i) => {
    params[name] = match[i + 1];
  });
  return { params };
}

Umsetzung unter iOS

func handleDeepLink(_ url: URL) {
    guard let route = DeepLinkRouter.match(
        url: url.absoluteString,
        platform: "ios"
    ) else {
        navigateToHome()
        return
    }

    // iOS-spezifische Konfiguration behandeln
    if let handoffActivity = route.platformConfig?.handoffActivity {
        setupHandoff(activityType: handoffActivity, url: url)
    }

    navigateTo(screen: route.screen, params: route.params)
}

private func setupHandoff(activityType: String, url: URL) {
    let activity = NSUserActivity(activityType: activityType)
    activity.webpageURL = url
    activity.isEligibleForHandoff = true
    UIApplication.shared.userActivity = activity
}

Umsetzung unter Android

fun handleDeepLink(intent: Intent) {
    val uri = intent.data ?: return
    val route = DeepLinkRouter.match(
        url = uri.toString(),
        platform = "android"
    ) ?: run {
        navigateToHome()
        return
    }

    // Android-spezifische Konfiguration behandeln
    route.platformConfig?.launchMode?.let { mode ->
        when (mode) {
            "singleTask" -> {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
                    Intent.FLAG_ACTIVITY_CLEAR_TOP)
            }
            "singleTop" -> {
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
            }
        }
    }

    navigateTo(screen = route.screen, params = route.params)
}

Fallbacks zwischen Plattformen behandeln

Wenn ein Deep Link auf eine plattformspezifische Funktion zeigt, definiere für die andere Plattform ein Fallback-Verhalten:

interface Route {
  path: string;
  screen: string;
  platforms: ('ios' | 'android' | 'web')[];
  fallback?: {
    screen: string;
    message?: string;
  };
}

const routes: Route[] = [
  {
    path: '/ar-preview/:productId',
    screen: 'ARPreview',
    platforms: ['ios'],
    fallback: {
      screen: 'ProductDetail',
      message: 'AR-Vorschau ist nur auf iOS verfügbar'
    }
  }
];

function resolveRoute(url: string, platform: string): RouteMatch {
  const route = findMatchingRoute(url);

  if (!route) {
    return { screen: 'Home', params: {} };
  }

  if (!route.platforms.includes(platform)) {
    // Plattform wird nicht unterstützt, also Fallback verwenden
    if (route.fallback) {
      return {
        screen: route.fallback.screen,
        params: extractParams(url, route.path),
        message: route.fallback.message
      };
    }
    return { screen: 'Home', params: {} };
  }

  return {
    screen: route.screen,
    params: extractParams(url, route.path)
  };
}

Plattformspezifische Routen wirken sich auf deine Verifizierungsdateien aus. Du musst Pfade nur in der Datei der Plattform eintragen, die sie unterstützt.

AASA (iOS)

Nimm nur iOS-Routen und gemeinsame Routen auf:

{
  "applinks": {
    "details": [{
      "appIDs": ["TEAMID.com.yourcompany.yourapp"],
      "components": [
        { "/": "/products/*" },
        { "/": "/offers/*" },
        { "/": "/ar-preview/*" },
        { "/": "/share/*" }
      ]
    }]
  }
}

AndroidManifest.xml

Nimm nur Android-Routen und gemeinsame Routen auf:

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https"
          android:host="yourdomain.com"
          android:pathPrefix="/products" />
    <data android:scheme="https"
          android:host="yourdomain.com"
          android:pathPrefix="/offers" />
    <data android:scheme="https"
          android:host="yourdomain.com"
          android:pathPrefix="/instant" />
    <data android:scheme="https"
          android:host="yourdomain.com"
          android:pathPrefix="/share" />
</intent-filter>

Unterschiede bei der Zurück-Navigation

Nachdem ein Deep Link geöffnet wurde, unterscheidet sich das Verhalten des Zurück-Buttons deutlich:

iOS

  • Das System stellt in der Statusleiste einen Link "Zurück zu [source app]" bereit.
  • Der Navigations-Stack deiner App startet neu, außer die App lief schon.
  • Nutzer erwarten, dass Wischen zurück zum übergeordneten Bildschirm führt, nicht zur Quell-App.
func navigateFromDeepLink(to screen: String, params: [String: String]) {
    // Navigations-Stack aufbauen, damit der Nutzer zurücknavigieren kann
    let homeVC = HomeViewController()
    let detailVC = makeViewController(screen: screen, params: params)

    navigationController?.setViewControllers([homeVC, detailVC], animated: false)
}

Android

  • Der Zurück-Button sollte dem Task-Stack der App.
  • Nutze TaskStackBuilder folgen, um einen sauberen Back-Stack aufzubauen:
fun navigateFromDeepLink(screen: String, params: Map<String, String>) {
    val detailIntent = makeIntent(screen, params)

    TaskStackBuilder.create(this)
        .addNextIntentWithParentStack(detailIntent)
        .startActivities()
}

Hinweise für plattformübergreifende Frameworks

React Native

Das Linking-Modul von React Native's Linking API kapselt den Einstiegspunkt der Plattform ab, aber für bestimmte Verhaltensweisen brauchst du unter Umständen trotzdem Plattformprüfungen:

import { Platform, Linking } from 'react-native';

function handleDeepLink(url: string) {
  const route = matchRoute(url, Platform.OS);

  if (!route) {
    navigation.navigate('Home');
    return;
  }

  // Platform-specific handling
  if (Platform.OS === 'ios' && route.iosConfig?.spotlightTitle) {
    // Index in Spotlight
    indexInSpotlight(route);
  }

  navigation.navigate(route.screen, route.params);
}

Flutter

Das Routing in Flutter ist plattformunabhängig, aber für plattformspezifische Features kannst du Platform Channels nutzen:

void handleDeepLink(Uri uri) {
  final route = matchRoute(uri.toString());

  if (route == null) {
    Navigator.of(context).pushReplacementNamed('/');
    return;
  }

  // Plattformspezifische Features über Method Channel
  if (Platform.isIOS && route.handoffActivity != null) {
    _methodChannel.invokeMethod('setupHandoff', {
      'activityType': route.handoffActivity,
      'url': uri.toString(),
    });
  }

  Navigator.of(context).pushNamed(
    route.screen,
    arguments: route.params,
  );
}

Plattformspezifische Routen testen

Teste jede Plattform separat:

# iOS: eine iOS-only-Route testen
xcrun simctl openurl booted "https://yourdomain.com/ar-preview/product123"

# Android: eine Android-only-Route testen
adb shell am start -a android.intent.action.VIEW \
  -d "https://yourdomain.com/instant/product123" \
  -c android.intent.category.BROWSABLE

# Geteilte Route auf beiden Plattformen testen
xcrun simctl openurl booted "https://yourdomain.com/products/abc123"
adb shell am start -a android.intent.action.VIEW \
  -d "https://yourdomain.com/products/abc123" \
  -c android.intent.category.BROWSABLE

Teste das Fallback-Verhalten, indem du plattformspezifische URLs an die falsche Plattform schickst:

# iOS-only-Route an Android senden (sollte auf den Fallback ausweichen)
adb shell am start -a android.intent.action.VIEW \
  -d "https://yourdomain.com/ar-preview/product123" \
  -c android.intent.category.BROWSABLE

Tolinku für plattformübergreifendes Routing

Tolinku hostet beide Verifizierungsdateien, AASA und assetlinks.json. Du trägst deine iOS- und Android-App-Daten in den Appspace-Einstellungen ein Appspace-Einstellungen, und Tolinku erzeugt daraus die passenden Verifizierungsdateien für jede Plattform. Routes kann dynamische Parameter Routen enthalten, die auf allen Plattformen gleich funktionieren.

Die Grundlagen zum Routing findest du unter Deep-Link-Routing: wie du Nutzer zum richtigen Screen leitest. Zu gemeinsamer Routing-Logik siehe plattformübergreifende Muster für die Link-Verarbeitung.

Deep-Linking-Tipps direkt in Ihr Postfach

Eine E-Mail pro Woche. Kein Spam.

Bereit für Deep Linking in deiner App?

Richte Universal Links, App Links, Deferred Deep Linking und Analysen in wenigen Minuten ein. Kostenlos starten.