From a7b08dbf1ff4939f486682734080c51060b9927b Mon Sep 17 00:00:00 2001 From: Mike Pesate <5579996+MikePT28@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:59:38 +0100 Subject: [PATCH] Adds support for iOS deeplink inside demos-appyx-navigation --- .../ios/src/iosMain/kotlin/main.ios.kt | 15 ++++++++++++++- demos/appyx-navigation/iosApp/iosApp/Info.plist | 13 +++++++++++++ demos/appyx-navigation/iosApp/iosApp/iOSApp.swift | 4 ++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/demos/appyx-navigation/ios/src/iosMain/kotlin/main.ios.kt b/demos/appyx-navigation/ios/src/iosMain/kotlin/main.ios.kt index bb8e55417..87e7c545d 100644 --- a/demos/appyx-navigation/ios/src/iosMain/kotlin/main.ios.kt +++ b/demos/appyx-navigation/ios/src/iosMain/kotlin/main.ios.kt @@ -15,7 +15,7 @@ import com.bumble.appyx.navigation.navigator.Navigator import com.bumble.appyx.navigation.node.root.RootNode import com.bumble.appyx.navigation.ui.AppyxSampleAppTheme import kotlinx.coroutines.flow.flowOf - +import platform.Foundation.NSURL private val integrationPoint = MainIntegrationPoint() private val navigator = Navigator() @@ -50,3 +50,16 @@ fun MainViewController() = ComposeUIViewController { }.also { uiViewController -> integrationPoint.setViewController(uiViewController) } + +@Suppress("FunctionNaming") +fun handleDeepLinks(url: NSURL) { + if (url.scheme == "appyx") { + when (url.host) { + // xcrun simctl openurl booted 'appyx://randomcake' + ("randomcake") -> navigator.goToARandomCakeWithDummyUser() + + // xcrun simctl openurl booted 'appyx://randomcake-wait' + ("randomcake-wait") -> navigator.goToARandomCake() + } + } +} \ No newline at end of file diff --git a/demos/appyx-navigation/iosApp/iosApp/Info.plist b/demos/appyx-navigation/iosApp/iosApp/Info.plist index 412e37812..ac82fa292 100644 --- a/demos/appyx-navigation/iosApp/iosApp/Info.plist +++ b/demos/appyx-navigation/iosApp/iosApp/Info.plist @@ -16,6 +16,19 @@ $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString 1.0 + CFBundleURLTypes + + + CFBundleTypeRole + Viewer + CFBundleURLName + com.bumble.appyx.Appyx + CFBundleURLSchemes + + appyx + + + CFBundleVersion 1 LSRequiresIPhoneOS diff --git a/demos/appyx-navigation/iosApp/iosApp/iOSApp.swift b/demos/appyx-navigation/iosApp/iosApp/iOSApp.swift index ab9cb1191..db59d50ed 100644 --- a/demos/appyx-navigation/iosApp/iosApp/iOSApp.swift +++ b/demos/appyx-navigation/iosApp/iosApp/iOSApp.swift @@ -1,4 +1,5 @@ import SwiftUI +import ios @main struct iOSApp: App { @@ -7,6 +8,9 @@ struct iOSApp: App { ZStack { Color.white.ignoresSafeArea(.all) // status bar color ContentView() + } + .onOpenURL { incomingURL in + Main_iosKt.handleDeepLinks(url: incomingURL) } } }