Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI 2 lifecycle - handle custom URL scheme

Tags:

ios

swift

swiftui

Until now we were able to handle custom URL schemes that launch the app using AppDelegate or SceneDelegate. But how is this possible using the new lifecycle?

I tried adding an @UIApplicationDelegateAdaptor with the application:openURL:options: function but that is never called. The closest I've got is using the Environment's scenePhase but that only tells the state of the scene (active, background etc.), not the incoming URL.

like image 563
Toma Avatar asked Sep 19 '25 01:09

Toma


1 Answers

You can use the onOpenURL(perform:) modifier either in the body of you App or Scene or on views in your hierachy. The modifier gets called multiple times as well, so you could set the state for each view individually. With that your AppDelegate no longer needs to know your whole navigagion, which is great.

like image 100
jlsiewert Avatar answered Sep 20 '25 16:09

jlsiewert