We have gotten the two UIKit targets working, and we just need to get SwiftUI on board.
SwiftUI is crazy easy to support.
In this post, we’ll integrate our URL Scheme into the SwiftUI app, and we’ll be editing the SwiftUIApp.swift
file.
Just under the ContentView(status: $status) line, add the following code:
.onOpenURL { inURL in
guard let query = inURL.query(),
let state = AppStatus(rawValue: query)
else { return }
status = state
}
That’s it. We’re done. We added an onOpenURL(perform:)
call to the main screen wrapper, so our callback gets executed, when the app is opened via a URL. This simply parses out the query, creates a state instance, and sets the state property, which forces the screen to reload.
Now, if you use the URL Scheme URLs for this app, you will get the expected behavior, whether foregrounding, or coming in from a “cold start”:
iul3://?off
iul3://?stop
iul3://?caution
iul3://?go
This is the release that has the code, up to this point.
Next, we’ll start work on converting our URL Schemes to Universal Links.