Freaked out for missing one small snippet in SwiftUI while using .onOpenUrl
I was developing a cross platform application with SwiftUI. This application is registered for one URL Type as “Owner”.
The registration for URL Type means adding the URL Scheme in Info section of your target.
So, My application is expected to open for URL consisting the above scheme. SwiftUI provides us with .onOpenURL modifier for opening url. This can be added from any view.
This functionality is quite normal and worked as expected. While adding a lot of functionalities to my app, I messed up my code which affected this onOpenUrl functionality . So, after debugging for some amount of quality time, I figured my mistake.
For adding one functionality(Accepting invitations for Shared CloudKit Database), I have added a custom scene delegate to my code. After adding this custom scene delegate, SwiftUI expected this delegate to take care of URL Handling. This is what exactly broken my code. So I fixed this by adding small snippet as shown below.
Key Take Away:
When adding a custom scene delegate, route the requests like onOpenURL and onContinueUserActivity to original delegate.
Also, I will be posting an article about using .onOpenURL with TabView and share the way I solved opening Bottom views inside a View Tree.
Thanks for Reading:))