I've defined a URL scheme for my application, and that's being honored by iOS. But the function that's supposed to handle the URL in my appliation (as documented here) is never called.
The documentation doesn't say exactly where this is supposed to go. I've tried it in my App struct:
@main
struct MyGreatApp: App
{
var body: some Scene
{
WindowGroup
{
MainView()
}
}
// Handle custom URLs, specifically the ones sent in invitation E-mails or texts.
func application(_ application: UIApplication,
open theURL: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:] ) -> Bool
{
// Determine who sent the URL.
let sendingAppID = options[.sourceApplication]
print("source application = \(sendingAppID ?? "Unknown")")
...
And I also tried putting this at the file level. No dice either way. Anybody have an idea why?
To head off things I've seen in other posts: I'm not using scenes, and there's no SceneDelegate.
So... for anyone who stumbles across this, the final (and a major) problem is that universal links do not work as documented, for two reasons:
- For unknown reasons,
the apple-app-site-associationfile will not work unless it has a content-type header applied to it by the Web server. This is not automatic and not necessary for any reason other than to work around this issue on Apple's end.
Take a look at this SO question for more info. I'm on Apache, so I used the following in .htaccess
<FilesMatch "apple-app-site-association">
ForceType application/json
</FilesMatch>
- This requirement is undocumented. Apple provides a complete example file in its doc, and debugging hints here: https://developer.apple.com/documentation/technotes/tn3155-debugging-universal-links
It neglects to mention the need to set up special handling on your Web server to slap an otherwise nonexistent header on this file.
So now my app is receiving universal inks, via the onOpenURL view-modifier. I haven't tried the method that's actually documented as the primary one, in the application delegate yet.
Also, even if I delete and reinstall my app, the user is not asked if he wants to open the link in my app; it just does it.
I encourage everyone to file feedback on the dysfunction of universal links that's due to this unnecessary header requirement.